Apache2: allow/disallow access to a directory by time on day
Let's say I have a directory I want to restrict access that way, so that users can access the directory only on like 6am to 6pm. I know how to do this by using PHP (using time()%86400
). But can I do it entirely using Apache's builtin functions (.htaccess or server apache2.conf) or other mods?
Solution 1:
You can deny access to certain directories depending on the time by placing the following code in your .htaccess file in the directory you want to control:
RewriteCond %{TIME_HOUR} ^(13|14|15)$
RewriteRule ^.*$ - [F,L]
The hours are based on 24 hours in a day (0-23) and each hour you wish to deny access should be seperated with a “|”.
In the above example, nobody could access the directory from 1-3pm.