开发者

htaccess redirect query string and discard

开发者 https://www.devze.com 2022-12-12 06:05 出处:网络
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/

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

精彩评论

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

关注公众号