2015-09-03 67 views
2

我试图重定向从;htaccess从多个网址重定向到单个并删除查询字符串

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

还有其他的网址,我不知道,所以希望一切从新闻重定向/ newsitem.asp 到

http://www.example.com/blog 

我使用

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

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

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

如何阻止查询字符串被追加?

我发现这个职位,但似乎无法使它工作 redirect a single URL to another - removing the query string

回答

1

您可以使用:

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

?到底会去掉所有预先存在的查询字符串。

更好的逃避DOT在正则表达式中,并确保在清除浏览器缓存后进行测试。

0

您需要添加一个“?”重写目标末尾

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

最后为空的问号很重要,因为它会丢弃来自url的原始查询字符串。

相关问题