问题
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