Forum Moderators: phranque
Is it possible to limit access using .htaccess for a certain time period of a day?
Say I don't want visitors between 2am and 6am. Is that possible to do with htaccess and mod_rewrite? And if so, would anyone have any pointers to where I can find more info on it. I've tried my best to search for it but can't find anything related.
Thanks in advance.
RewriteCond %{TIME_HOUR} ^0[2-5]$
RewriteCond %{HTTP_USER_AGENT} !(Googlebot¦Slurp¦msnbot¦Teoma) [NC]
RewriteRule ^$¦^index\.html$ http://www.example.com/we-are-closed.html [R=302,L]
I would recommend you send the Vary: User-Agent header in response to home page requests, since the content will now change based on the requesting user-agent, and this can cause problems with network caches. You will also need to mark the "We're closed" page as expiring at 6:00 AM. Use Apache mod_headers and mod_expires to mark the files appropriately.
You will also need to put the <meta name="robots" content="nocache"> tag on every page that your want to limit access to. Otherwise, the original page will alwasy be shown in the search engines' cached-page views, which will partially defeat your purpose.
I can't say I really recommend this overall approach, though, because the Web is never closed. If you have some specific problem, like phone calls in the middle of the night, you might consider fixing just that problem, by not showing the phone number at night, for example.
Replace the broken pipe "¦" character above with a solid pipe character from your keyboard before use; Posting on this board modifies the pipe character.
For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].
Jim
[edited by: jdMorgan at 11:35 pm (utc) on Nov. 2, 2006]
The reason for having 'opening hours' is because the moderator of a specific forum I host wants her forum closed when she's not around... I have strongly recommended against it but it is her forum and I'll do anything for her :-D