在301重定向删除查询字符串 [英] Remove query string during a 301 redirect
问题描述
我想301以下网址
http://www.site.com/reviews/4f64d2862c16bf4ae40000b4?sort=all-positive
到
http://www.site.com/reviews
通过使用
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
如何删除后,究竟是什么检讨ID的所有查询字符串?基本上问号,一切之后,它需要去。任何想法?
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?
谢谢!
推荐答案
您必须使用此重写规则:重写规则^评论/([A-FA-F0-9] +)$ HTTP? //www.site.com/reviews/$1? [L,R = 301]
$ 1会将ID在URL的末尾时,?删除的查询。
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.
我也改变了AF为AF,但我不认为这时,只需要。
I have also changed "A-f" to "A-F", but I do not think this is neccessary.
修改 目前已经在SO类似的问题:<一href="http://stackoverflow.com/questions/3457022/mod-rewrite-remove-query-string-from-url">mod_rewrite:从URL删除查询字符串?
Edit There is already a similar question in SO: mod_rewrite: remove query string from URL?
这篇关于在301重定向删除查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!