views:

220

answers:

2

Hi there,

I was using a .htaccess redirect 301 to redirect a URL which then appended all the query string elements to the end, leaving me with some URLs indexed in Google as /store/product/?d=department&s=section&p=product.

I have fixed the redirect by using a RewriteRule instead which doesn't append the query strings, however I'm stuck trying to rewrite the old redirected URLs with the query strings back to the original URLs (as these are looking like two different URLs to Google now).

I have managed to get a RewriteRule to sort of work, in that /store/product/xxxxx redirects to /store/product/ as it should, it just doesn't seem to work with the whole query string of.

What I have been using is:

RewriteRule ^store/product/([a-zA-Z0-9\-_\?=&]+)$ http://www.example.com/store/product/ [NC,R=301,L]

or

RewriteRule ^store/product/\?d=department&s=section&p=product$ http://www.example.com/store/product/ [NC,R=301,L]

Hope that all makes sense!

Many thanks

A: 
RewriteCond %{QUERY_STRING} !^$
RewriteRule ^store/product/.*$ http://www.example.com/store/product/? [NC,R=301,L]
Ignacio Vazquez-Abrams
Hi there this seems to give me a re-write loop, is there any way to make the re-write only if there is definately something in the query string ?
stukerr
Absolutely. Fixed.
Ignacio Vazquez-Abrams
Great stuff! Many thanks
stukerr
A: 

You need to specify an empty query in your substitution to not have the original one automatically appended to the new URL:

RewriteRule ^store/product/[a-zA-Z0-9\-_=&]+$ http://www.example.com/store/product/? [NC,R=301,L]

Note the ? at the end of the substitution URL.

Gumbo