9

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?

  • 1
    What if the users are spread over different time zones? – Gerald Schneider Jan 4 '17 at 15:02
13

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.