htaccess的重写,除去查询字符串 [英] htaccess rewrite to remove query string
本文介绍了htaccess的重写,除去查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要重写如下:
http://www.mystuff.com/drinks/category/beer?page=1
到
https://www.mystuff.com/food-drink/beer/ale
无论我怎么努力的URI改写为新的地址,但它保持连接的查询字符串。我需要减肥这一点。我试过这么多的选择,没有似乎工作,可有人ofgfer一些建议。 我认为这将做到这一点,但没有:
No matter what I try the URI rewrite to the new address but it keeps the query string attached. I need to lose this. I've tried so many options and none seem to work, can anybody ofgfer some advice. I thought this would do it, but no:
RewriteCond %{QUERY_STRING} (.*)(?:^|&)page=(?:[^&]*)((?:&|$).*)
RewriteCond %1%2 (^|&)([^&].*|$)
RewriteRule ^(/drinks/category/beer)$ https://www.mystuff.com/food-drink/beer/ale [R=301, L]
有人能帮忙吗?
Can anybody help?
推荐答案
您需要添加一个空的查询字符串截断它改写。添加一个
来重写的末尾:
You need to add an empty query string to truncate it on the rewrite. Add a single ?
to the end of the rewrite:
RewriteCond %{QUERY_STRING} (.*)(?:^|&)page=(?:[^&]*)((?:&|$).*)
RewriteCond %1%2 (^|&)([^&].*|$)
RewriteRule ^(/drinks/category/beer)$ https://www.mystuff.com/food-drink/beer/ale? [R=301, L]
这篇关于htaccess的重写,除去查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文