【问题标题】:.htaccess redirect without query parameters.htaccess 不带查询参数的重定向
【发布时间】:2013-04-07 18:30:00
【问题描述】:

我更改了一个网站,现在 Google 网站管理员正在加载数百个“未找到”网址:

http://www.domain.com/images/picture.php?idphotos=720,404,,4/1/13,Not found

picture.php 不再存在,所以我创建了一个 .htaccess 条目来重定向站点的根目录:

Redirect 301 /images/picture.php. /

现在的问题是任何查询参数也在重定向中发送:

http://www.domain.com/?idphotos=720

如何创建不包含查询参数的重定向,例如像这样:

http://www.domain.com/

【问题讨论】:

    标签: regex .htaccess seo


    【解决方案1】:

    试试这个(注意尾随?):

    RewriteCond %{QUERY_STRING} !=""
    RewriteRule . http://www.domain.com/?
    

    【讨论】:

      【解决方案2】:

      或者使用 Apache 2.4.0 中的 QSD 标志

      RewriteCond %{QUERY_STRING} !=""    
      RewriteRule . http://www.domain.com/ [L,R=301,QSD]
      

      http://httpd.apache.org/docs/current/en/rewrite/flags.html#flag_qsd

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-01-22
        • 1970-01-01
        • 2011-03-16
        相关资源
        最近更新 更多