开发者

htaccess redirect query string and discard

Having trouble with redirecting a dynamic URL. This is what I want to accomplish:

Redirect 301 /content/index.php?id=423 http://www.domain.com/new-page/

I tried this

RewriteCond %{QUERY_STRING} ^(([^&]*&)*)id=423$
RewriteRule ^co开发者_JAVA技巧ntent/index\.php$ http://www.domain.com/new-page [L,R=301]

but had no luck. Thank you! ps/ I lost some para work with this code

RewriteRule ^([^.]+)/([A-Za-z]*)-([^.]+)-([0-9]+).html$ $1/$4-$2-$3.html [L,R=301]


You need to specify the query in the replacement URL. Otherwise the original query is taken:

RewriteCond %{QUERY_STRING} ^id=423$
RewriteRule ^content/index\.php$ http://example.com/new-page? [L,R=301]

And if you want to preserve other URL arguments, try this:

RewriteCond %{QUERY_STRING} ^(([^&]*&)*)id=423&*([^&].*)?$
RewriteRule ^content/index\.php$ http://example.com/new-page?%1%3 [L,R=301]
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜