【问题标题】:htaccess redirect from multiple urls to single and remove query stringhtaccess 从多个 url 重定向到单个并删除查询字符串
【发布时间】:2015-09-03 11:03:29
【问题描述】:

我正在尝试重定向网址;

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

还有其他我不知道的 url,所以想从 news/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

【问题讨论】:

    标签: .htaccess mod-rewrite redirect


    【解决方案1】:

    你可以使用:

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

    ? 最后会剥离任何预先存在的查询字符串。

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

    【讨论】:

      【解决方案2】:

      您需要添加一个“?”在你的重写目标结束时

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

      末尾的空问号很重要,因为它会丢弃 url 中的原始查询字符串。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多