Differences between revisions 2 and 3
Revision 2 as of 2009-01-27 18:24:16
Size: 1397
Editor: ThomasAllen
Comment: Fixed space bug in final recipe
Revision 3 as of 2009-09-20 22:13:22
Size: 1397
Editor: localhost
Comment: converted to 1.6 markup
No differences found!

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$             /foo.day.html [PT]
RewriteRule   ^/foo\.html$             /foo.night.html [PT]


This ruleset will rewrite /foo.html to /foo.day.html 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.

RewriteTimeOfDay (last edited 2009-09-20 22:13:22 by localhost)