multiple specific 301 Redirects

Using mod_rewrite to handle various content issues

multiple specific 301 Redirects

Postby raisinlove » Mon Nov 10, 2008 1:50 pm

Hello,
looking through the forums, I found how to permanently redirect a querystring based url to a directory. However, I havent figured out how to reproduce it for every variable/url combination.

For example, when I use the following, it works:

Code: Select all
RewriteCond %{QUERY_STRING} ^(.*&)?p=1(&.*)?$ [NC]
RewriteRule ^index\.php$ /fr/neufs/? [NC,R=301,L]
RewriteRule ^fr/index\.php$ /fr/neufs/? [NC,R=301,L]


But if I attempt to repeat the same code for each, only the first one works:

Code: Select all
RewriteCond %{QUERY_STRING} ^(.*&)?p=1(&.*)?$ [NC]
RewriteRule ^index\.php$ /fr/neufs/? [NC,R=301,L]
RewriteRule ^fr/index\.php$ /fr/neufs/? [NC,R=301,L]

RewriteCond %{QUERY_STRING} ^(.*&)?p=2(&.*)?$ [NC]
RewriteRule ^index\.php$ /fr/inventaire/? [NC,R=301,L]
RewriteRule ^fr/index\.php?p=2$ /fr/inventaire/? [NC,R=301,L]

RewriteCond %{QUERY_STRING} ^(.*&)?p=3(&.*)?$ [NC]
RewriteRule ^index\.php$ /fr/location/? [NC,R=301,L]
RewriteRule ^fr/index\.php$ /fr/location/? [NC,R=301,L]

RewriteCond %{QUERY_STRING} ^(.*&)?p=14(&.*)?$ [NC]
RewriteRule ^index\.php$ /fr/location/? [NC,R=301,L]
RewriteRule ^fr/index\.php$ /fr/location/? [NC,R=301,L]

RewriteCond %{QUERY_STRING} ^(.*&)?p=4(&.*)?$ [NC]
RewriteRule ^index\.php$ /fr/services-et-pieces/? [NC,R=301,L]
RewriteRule ^fr/index\.php$ /fr/services-et-pieces/? [NC,R=301,L]

RewriteCond %{QUERY_STRING} ^(.*&)?p=5(&.*)?$ [NC]
RewriteRule ^index\.php$ /fr/evenements/? [NC,R=301,L]
RewriteRule ^fr/index\.php$ /fr/evenements/? [NC,R=301,L]

RewriteCond %{QUERY_STRING} ^(.*&)?p=6(&.*)?$ [NC]
RewriteRule ^index\.php$ /fr/liens/? [NC,R=301,L]
RewriteRule ^fr/index\.php$ /fr/liens/? [NC,R=301,L]

RewriteCond %{QUERY_STRING} ^(.*&)?p=7(&.*)?$ [NC]
RewriteRule ^index\.php$ /fr/promotions/? [NC,R=301,L]
RewriteRule ^fr/index\.php$ /fr/promotions/? [NC,R=301,L]

RewriteCond %{QUERY_STRING} ^(.*&)?p=8(&.*)?$ [NC]
RewriteRule ^index\.php$ /fr/nous-joindre/? [NC,R=301,L]
RewriteRule ^fr/index\.php$ /fr/nous-joindre/? [NC,R=301,L]

RewriteCond %{QUERY_STRING} ^(.*&)?p=10(&.*)?$ [NC]
RewriteRule ^index\.php$ /fr/neufs/? [NC,R=301,L]
RewriteRule ^fr/index\.php$ /fr/neufs/? [NC,R=301,L]

RewriteCond %{QUERY_STRING} ^(.*&)?p=12(&.*)?$ [NC]
RewriteRule ^index\.php$ /fr/neufs/? [NC,R=301,L]
RewriteRule ^fr/index\.php$ /fr/neufs/? [NC,R=301,L]

RewriteCond %{QUERY_STRING} ^(.*&)?p=11(&.*)?$ [NC]
RewriteRule ^index\.php$ /fr/neufs/? [NC,R=301,L]
RewriteRule ^fr/index\.php$ /fr/neufs/? [NC,R=301,L]

RewriteCond %{QUERY_STRING} ^(.*&)?p=13(&.*)?$ [NC]
RewriteRule ^index\.php$ /fr/promotions/? [NC,R=301,L]
RewriteRule ^fr/index\.php$ /fr/promotions/? [NC,R=301,L]


What am I doing wrong here?
raisinlove
 
Posts: 8
Joined: Thu Aug 19, 2004 2:54 am

Postby richardk » Mon Nov 10, 2008 2:26 pm

A RewriteCond only applies to the next rule. Try repeating
Code: Select all
RewriteCond %{QUERY_STRING} ^(.*&)?p=1(&.*)?$ [NC]
RewriteRule ^(fr/)?index\.php$ /fr/neufs/? [NC,R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby raisinlove » Tue Nov 11, 2008 6:24 am

Thank you! So repeating the rule canceled the first one each time... this also saves up on lines :) Works like a charm...
raisinlove
 
Posts: 8
Joined: Thu Aug 19, 2004 2:54 am


Return to Content

Who is online

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

cron