Redirect URL based on Current Month

Oh, the strange things mod_rewrite does!

Redirect URL based on Current Month

Postby gckmac » Thu Apr 03, 2008 12:24 pm

I've got a website that, by scripting, shows events for current month, i.e., www.maine.info/events/music/april.php

I want to be able to give out a static/fixed URL, e.g., www.maine.info/events/music.php (or something like that) which, via mod_rewrite, will also direct to the current month. Currently April, so it would automatically go to www.maine.info/events/music/april.php. Next month, it would automatically go to www.maine.info/events/music/may.php

I think the RewriteCond is "RewriteCond %{TIME_MON}" but I am not smart enough to figure out how to write the complete .htaccess rule itself. Help please!

gckmac
gckmac
 
Posts: 2
Joined: Thu Apr 03, 2008 12:19 pm

Postby richardk » Thu Apr 03, 2008 3:47 pm

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{TIME_MON}january  ^1(january)$ [OR]
# ... etc. ...
RewriteCond %{TIME_MON}november ^11(november)$ [OR]
RewriteCond %{TIME_MON}december ^12(december)$
RewriteRule ^events/music\.php$ /events/music/%1.php [QSA,L]

You have to fill in the missing RewriteConds. If April does not match with "4", it might need to be "04".
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Brilliant!

Postby gckmac » Thu Apr 03, 2008 6:20 pm

Richard,

Thank you, you are brilliant! It works with "04" Here is the result:

http://www.maine.info/events/music.php .... it goes to the current month as required.

I owe you a cup of java!

gckmac
gckmac
 
Posts: 2
Joined: Thu Apr 03, 2008 12:19 pm


Return to Idiosyncrasies

Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron