htaccess从多个url重定向到单个并删除查询字符串

时间:2015-09-03 11:03:29

标签: .htaccess mod-rewrite redirect

我正在尝试重定向网址;

http://www.example.com/news/newsitem.asp?story=20130227
http://www.example.com/news/newsitem.asp?story=20148893

还有其他我不知道的网址,所以想要重定向来自news / newsitem.asp的所有内容 到

http://www.example.com/blog

我正在使用

RewriteRule ^news/newsitem.asp http://www.example.com/blog [R=301,L]

但结果会将查询字符串添加到结尾

result = http://www.example.com/blog?story=20130227

如何停止追加查询字符串?

我确实找到了这篇文章,但似乎无法使其发挥作用 redirect a single URL to another - removing the query string

2 个答案:

答案 0 :(得分:1)

您可以使用:

RewriteRule ^news/newsitem\.asp$ /blog/? [R=301,L,NC]
最后

?将删除任何预先存在的查询字符串。

最好在正则表达式中转义DOT,并确保在清除浏览器缓存后对其进行测试。

答案 1 :(得分:0)

你需要添加"?"在重写目标结束时

RewriteRule ^news/newsitem.asp$ http://www.example.com/blog? [R=301,L]

最后的空问号非常重要,因为它会从网址中丢弃原始查询字符串。

相关问题