Remove query string during a 301 redirect

不问归期 提交于 2019-12-12 04:15:32

问题


I'm trying to 301 the following url

http://www.site.com/reviews/4f64d2862c16bf4ae40000b4?sort=all-positive 

to

http://www.site.com/reviews

By using

RewriteRule ^reviews/([a-fA-f0-9]+)?$ http://www.site.com/reviews [L,R=301]

But that redirects me to

http://www.site.com/reviews?sort=all-positive

How can I remove all query strings after what was the review id? Basically the question mark and everything after it needs to go. Any ideas?

Thanks!


回答1:


You have to use this RewriteRule: RewriteRule ^reviews/([a-fA-F0-9]+)?$ http://www.site.com/reviews/$1? [L,R=301] The $1 puts the id at the end of the url, the "?" deletes the query.

I have also changed "A-f" to "A-F", but I do not think this is neccessary.

Edit There is already a similar question in SO: mod_rewrite: remove query string from URL?



来源:https://stackoverflow.com/questions/10726439/remove-query-string-during-a-301-redirect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!