开发者

mod_rewrite for specific dynamic pages

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 p开发者_如何学JAVAossible 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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜