【问题标题】:Persistent query strings being passed in htaccess (mod_rewrite)在 htaccess (mod_rewrite) 中传递的持久查询字符串
【发布时间】:2012-06-11 10:23:25
【问题描述】:

我遇到的问题是查询字符串通过重定向持续存在。即,每当我尝试重定向类型的 URL 时

RewriteRule ^oldsite/product/productname.aspx http://subdomain.newsite.com/product [L,R=301]

这很好用 - 没问题。

但是,当我尝试使用任何带有查询字符串的东西时,例如:

RewriteRule ^oldsite/product/productname.aspx?=QUERYSTRING http://subdomain.newsite.com/product [L,R=301]

重定向有效,但是当我使用标头检查器检查它时,我最终得到以下结果:

http://subdomain.newsite.com/product?=QUERYSTRING

即- 它从旧 URL 传递查询字符串,我不希望它这样做。

我检查了一堆资源,但似乎找不到一个简单的解决方案。方参数括号中是否缺少我的标志? (对不起,如果我使用了错误的术语,mod_rewrite 的新手。)

【问题讨论】:

    标签: .htaccess mod-rewrite seo


    【解决方案1】:

    如果你附加一个 ?到您的目标 URL,查询字符串将从重定向中删除:

    RewriteRule ^oldsite/product/productname.aspx http://subdomain.newsite.com/product? [L,R=301]
    

    【讨论】:

      【解决方案2】:

      是的,只要您没有对其进行任何修改(例如,新 URL 没有查询字符串),即使在重定向时,查询字符串也会自动复制到新 URL。

      例如: /register -> /login.php?action=register -- 结果总是/login.php?action=register,即使原始网址是/register?say=bla-bla但是对于/register -> /login.php,查询字符串将始终被复制,因此/register?say=bla-bla 将变为/login.php?say=bla-bla

      那么,需要做什么?您需要提供一些查询字符串——在您的情况下,查询字符串应该为空。

      怎么做?只需在新网址末尾添加?

      RewriteRule ^oldsite/product/productname.aspx http://subdomain.newsite.com/product? [L,R=301]
      

      【讨论】:

        猜你喜欢
        • 2016-03-26
        • 1970-01-01
        • 2013-02-25
        • 1970-01-01
        • 2012-06-25
        • 1970-01-01
        • 1970-01-01
        • 2015-08-16
        • 1970-01-01
        相关资源
        最近更新 更多