This seems so simple.. why won't this work??

Oh, the strange things mod_rewrite does!

This seems so simple.. why won't this work??

Postby jonblock » Wed Mar 15, 2006 12:42 pm

For the following URL:

http://www.example.com/test.html?2006

I want mod rewrite to say: If the current year (Today is March 15th, 2006) is passed inside the query string, then do a rewrite to apache.org.

I absolutly cannot get this to work.

Here's the code I tried:
------
RewriteCond %{TIME_YEAR} %{QUERY_STRING}
RewriteRule ^.*$ http://www.apache.org [R]
------

I need to perform this task using mod_rewrite (I can't use php or perl etc).

Help!

Thank you,
Jon
:x
jonblock
 
Posts: 15
Joined: Wed Oct 05, 2005 8:11 am
Location: Boston, MA

Postby richardk » Tue Apr 11, 2006 11:40 am

You can't put variables in the pattern part of RewriteRules and RewriteConds. It can be done with a backrefrence:

Code: Select all
RewriteCond %{QUERY_STRING}---%{TIME_YEAR} ^([0-9]+)---\1$
RewriteRule .* http://apache.org/ [R,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Idiosyncrasies

Who is online

Users browsing this forum: No registered users and 4 guests

cron