Time Based URL Rewriting

On July 7, 2010, in Web Development, by Anuj Gakhar

I have used several URL Rewriting engines in my career and one of my favorites is the Apache mod_rewrite. It is a very powerful rewrite engine and today I learned something new about it. Basically, I was browsing the Practical Driving Test Booking page and I noticed a message saying that this system is only available between 6AM and midnight. That’s when it occurred to me that URL rewriting could be used for doing such a thing.

I started looking for this and sure enough this is one of the features of mod_rewrite. Here is the code to achieve this :-

RewriteEngine On

RewriteCond %{TIME_HOUR}%{TIME_MIN} >2359
RewriteCond %{TIME_HOUR}%{TIME_MIN} <0600
RewriteRule ^index\.cfm$ /systemdown.html [L]
The above code makes sure that the time is more than 23:59 and less than 06:00 and if it is, rewrites index.cfm to systemdown.html and the URL stays the same. No code changes required at all.
Now, that is cool!
 

3 Responses to Time Based URL Rewriting

  1. Wish I had more to say here – but cool tip!

  2. shortener says:

    Thanks a bunch for sharing this with all folks you actually recognize what you’re talking approximately! Bookmarked. Kindly also seek advice from my web site =). We may have a hyperlink change agreement among us

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 445 other subscribers

© 2011 Anuj Gakhar
%d bloggers like this: