.htaccess redirect: help needed


I urgently need to redirect two specific URLs.

An online store I’ve developed uses overly-complicated URLs for the products. However, two of these URLs have had SEO links built for them and I therefore want to re-direct them to the new URL format.

The old format:

New format:

I know this isn’t perfect, but it’s the format I want to proceed with for now.

My attempt at the redirection was this:

Redirect 301 /online-store/product.php?year=2009&month=06&day=15&title=product-name http://www.mydomain.co.uk/online-store/product.php?id=38

It doesn’t work…


That’s what I would have suggested so, if it didn’t work for you, then mod_alias can’t look at the {QUERY_STRING} variable => you’re forced to use mod_rewrite:

RewriteEngine on
RewriteCond %{QUERY_STRING} year=2009
RewriteCond %{QUERY_STRING} month=06
RewriteCond %{QUERY_STRING} day=15
RewriteCond %{QUERY_STRING} title=product-name
RewriteRule ^online-store/product\\.php http://www.mydomain.co.uk/online-store/product.php?id=38 [R=301,L]

Please note that I parsed your query string because the order may be different (if not, recombine them with the &'s) - they will AND with the order not being a factor.



In the end I used php to perform a 301 redirect… Hopefully this will be sufficient.

Many thanks all the same.