tags:

views:

37

answers:

2

I have some old product pages showing up in search for a redesigned site.

The old pages are like this: www.site.com/mycart/index.php?act=viewProd&productId=34

I have static pages that I want these to go to.

so I want

redirect 301 /mycart/index.php?act=viewProd&productId=34 http://www.site.com/prod-name1

I know I can't do this with "redirect 301" since it is not a static page.

I would like to know the best way to approach this.

I will need to have a rule for each redirect since there is no correlation between old structure and new pages.

would it be possible maybe to just match on productId=34

RewriteRule [url contains productId=34] http://www.site.com/prod-name1? [R=301, L]

If that would be a valid solution, how would I go about matching on "productId=34".

Any help would be appreciated.

A: 

Why wouldn't you want to use a 301 in this case? Here's a tutorial on changing dynamic URLs to static URLs. If you are truly redirecting to static pages, you want an external redirect. If you are keeping your PHP files, and want to put a pretty URL in front of it, you want to do an internal rewrite, i.e. when the request comes in for /prod-name-1, route it internally to /mycart/index.php?productId=34, but don't send a 301.

dcwatson
Please re-read the above comments. I do want to use a 301 redirect.I would prefer to just use redirect 301 oldpage http://www.newsite.com/product-name But unfortunately, the old cart structure got dynamic pages indexed with ? marks in the urls, and apache redirect won't handle those.
merlincam
+1  A: 

You need to use RewriteCond to test the query:

RewriteCond %{QUERY_STRING} ^(&[^&]*)*productId=34(&|$)
RewriteRule ^mycart/index\.php$ /prod-name1? [L,R=301]

The ^(&[^&]*)* before and (&|$) after productId=34 is just to only rewrite if productId=34 is a complete URL argument and not just part of one like productId=34567 or foobarproductId=34.

Gumbo
I ended up using this (Before I saw your answer):RewriteCond %{QUERY_STRING} .*productId=34.*RewriteRule (.*) http://www.site.com/view/product-name?I feel that your solution is more robust, and maybe slightly more correct.
merlincam