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 Day | TIME_WDAY value |
Sunday | 0 |
Monday | 1 |
Tuesday | 2 |
Wednesday | 3 |
Thursday | 4 |
Friday | 5 |
Saturday | 6 |
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.
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 Name | Description |
---|---|
TIME_YEAR | The current year (e.g. 2010) |
TIME_MON | The current month (01, …, 12) |
TIME_DAY | The current day of the month (01, …) |
TIME_HOUR | The hour part of the current time (00, …, 23) |
TIME_MIN | The minute part of the current time |
TIME_SEC | The second part of the current time |
TIME_WDAY | The day of the week (starting with 0 for Sunday) |
TIME | The date and time in the format 20101231235959 |
SERVER_SOFTWARE | The server version string |
API_VERSION | The date of the API version (module magic number) |
Resources:
Server variables
mod_rewrite info