Block site access on specific days and hours

Do you want to block access to your site outside of working hours or on specific days? We’ll show you how to accomplish this.

To prevent access on specific days of the week, use:

# prevent access on specific days
# site will not be accesible on Sundays
RewriteCond %{TIME_WDAY} ^0$
RewriteRule ^.*$ - [F,L]

The TIME_WDAY variable takes values from 0 to 6 as:

Calendar DayTIME_WDAY value

To block access on specific hours:

# prevent access from 12:00 to 14:00
RewriteCond %{TIME_HOUR} ^(12|13)$
RewriteRule ^.*$ - [F,L]

Notice that using a TIME_HOUR value of 12, for example, means the site will not be accessible between 12:00 and 12:59.

In both of the above examples, the server will generate a 403 server error and no further rules will be processed.

time hour time day2
403 HTTP Forbidden message

NOTICE – Double check the system date before using these rules on a production site.

Below you have the time-related system variables you can use.

Variable NameDescription
TIME_YEARThe current year (e.g. 2010)
TIME_MONThe current month (01, …, 12)
TIME_DAYThe current day of the month (01, …)
TIME_HOURThe hour part of the current time (00, …, 23)
TIME_MINThe minute part of the current time
TIME_SECThe second part of the current time
TIME_WDAYThe day of the week (starting with 0 for Sunday)
TIMEThe date and time in the format 20101231235959
SERVER_SOFTWAREThe server version string
API_VERSIONThe date of the API version (module magic number)

Server variables
mod_rewrite info

Leave a Reply