Our website would like to use cookies to store information on your computer. You may delete and block all cookies from this site, but parts of the site will not work as a result. Find out more about how we use cookies.

Login or Register

Powered by
Powered by Novacaster
 
mod_rewrite notes
by Simon at 17:15 07/12/05 (Forum::Technical Advice::General)
I frequently find myself in need of memory jogging regarding mod_rewrite.
Since I'm fed up of Googling, I'm going to start noting stuff down here.
--
simon
<< Trivial, I thought. Wanted: Someone cleverer than ... >>
View Comments (Threaded Mode) Printer Version
mod_rewrite notes Simon - 17:15 07/12/05
Re: mod_rewrite notes: Redirect based on URI and Query String Simon - 17:20 07/12/05
RewriteCond %{QUERY_STRING} ^id=3209&n=[0-9]+$ [OR]
RewriteCond %{QUERY_STRING} ^id=3209$ [OR]
RewriteCond %{QUERY_STRING} ^n=[0-9]+&id=3209$
RewriteRule ^/showarticle.pl$ /index.pl?section=267&n=3621 [R=301,last]

This rewrites /showarticle.pl?[permuation of params] to /index.pl?[other params] as a Permanent Redirect (301), not Temporary (302), and uses [last] to terminate the rule checks immediately we have a match.

Worked out when I realised that you can't put the QUERY_STRING on the end of the URI in the RewriteRule - it has to be handled as a RewriteCond instead.

This may seem obvious to you as indeed it's now obvious to me too.
--
simon

Re: mod_rewrite notes: Redirect based on URI and Query String Hugo van der Sanden - 00:01 08/12/05
Don't forget to allow for /[&;]/ in the future. :)

Hugo

Re: mod_rewrite notes: Redirect based on URI and Query String Simon - 09:25 08/12/05
Good point, well made.

Fixing up now.
--
simon

Re: mod_rewrite notes: Redirect based on URI and Query String David Crowson - 15:43 08/12/05
>fixing up now

code junkie :)

--
bombholio