【问题标题】:htaccess - how to redirect url with params to base urlhtaccess - 如何将带有参数的 url 重定向到基本 url
【发布时间】:2015-04-29 23:53:22
【问题描述】:

我正在尝试将最后带有参数的 page.html 重定向到不带参数的基本 url。我知道我应该使用 mod rewrite,但我无法弄清楚规则。我们将不胜感激。

这是场景: 我在 htaccess 中尝试过,但这条规则不起作用:

redirect 301 "/page.html?p=2" http://www.domain.com/page.html

我通过阅读 stackoverflow 上的其他帖子了解到我应该写类似的东西

^page\.html$ http://www.domain.com/page.html [QSA,NC,R=301,L]

[QSA,NC,R=301,L] 末尾的规则是不正确的。我想不通。我只是想用p=2 参数为这个url 做一个301,没有其他参数。

然后对其他页面处理这条规则之后的剩余规则。

【问题讨论】:

    标签: apache .htaccess mod-rewrite


    【解决方案1】:

    你可以把这段代码放在你的root htaccess中

    RewriteEngine On
    
    RewriteCond %{QUERY_STRING} ^p=2$ [NC]
    RewriteRule ^page\.html$ /page.html? [R=301,L]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-01
      • 2018-12-21
      • 2016-04-27
      • 2018-03-24
      • 2014-04-29
      • 1970-01-01
      相关资源
      最近更新 更多