【问题标题】:htaccess redirect query string to homepagehtaccess 将查询字符串重定向到主页
【发布时间】:2015-05-08 17:59:23
【问题描述】:

对于我的一个网站,谷歌开始索引页面,例如:

www.domain.com/?index.php=en-id1&itemid=3711&view=21

他们在一天之内就将其中的几个编入了索引,使该网站看起来有数千个页面。

除了尝试清理网站、修复安全问题以及让谷歌尝试从索引中删除这些页面。我想将这些页面重定向到主页本身,因此它会从 URL 中完全删除查询字符串。

这是一个 wordpress 网站,所以我在 htaccess 中的 wordpress 重写规则上方放置了一个这样的重写条件:

<IfModule mod_rewrite.c>
RewriteEngine On 
RewriteCond %{QUERY_STRING} ^index.php*$
RewriteRule ^index\.php$ http://domain.com/%1 [R=301,L]
</IfModule>

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

如何将所有以 /?index.php=en-id 开头的页面重定向到我的主页?

【问题讨论】:

    标签: php wordpress apache .htaccess redirect


    【解决方案1】:

    你可以试试这个:

    <IfModule mod_rewrite.c>
      RewriteEngine On 
      RewriteCond %{QUERY_STRING} ^index.php
      RewriteRule ^(.*)$ http://domain.com/$1? [R=301,L]
    </IfModule>
    

    只有以“index.php”开头的查询字符串才会被删除。 此外,上面的 sn-p 将重定向到您要访问的任何页面。 如果您希望任何以“index.php”开头的查询的请求always 重定向到主页。 您可以进行以下调整:

    <IfModule mod_rewrite.c>
      RewriteEngine On 
      RewriteCond %{QUERY_STRING} ^index.php
      RewriteRule ^ http://domain.com/? [R=301,L]
    </IfModule>
    

    其他资源:

    htaccess 301 redirect - Remove query string (QSA)

    【讨论】:

      猜你喜欢
      • 2013-08-06
      • 2016-04-25
      • 2015-12-13
      • 2018-12-02
      • 2020-12-14
      • 2015-03-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多