Redirect based on time of day


You wish to serve different content depending on what time of day it is


RewriteEngine on
RewriteCond   %{TIME_HOUR}%{TIME_MIN} >0700
RewriteCond   %{TIME_HOUR}%{TIME_MIN} <1900
RewriteRule   ^/foo\.html$             / [PT]
RewriteRule   ^/foo\.html$             /foo.night.html [PT]


This ruleset will rewrite /foo.html to / between 0700 (7am) and 1900 (7pm), and will rewrite it to /foo.night.html the rest of the time. The RewriteCond causes the following RewriteRule to be skipped if the condition is not met, which is how we end up with an if ... else kind of syntax.

Serve a contest page during a contest


Serve a contest page during a contest, but don't bug people with it more than once a day.


RewriteCond %{TIME} >20050701080000
RewriteCond %{TIME} <20050705170000
RewriteCond %{HTTP_COOKIE} !frontdoor=yes
RewriteRule ^/index\.html$  /contest.html \


If the date is between the two values (8am on July 1 and 5pm on July 5) and if they haven't already come through the front door, redirect /index.html to /contest.html and set a cookie for a day so that they don't have this happen again until tomorrow.

  • No labels