htaccess 将查询字符串重定向到主页
htaccess redirect query string to homepage
对于我的一个网站,google 开始索引如下页面:
www.domain.com/?index.php=en-id1&itemid=3711&view=21
他们在一天之内就将其中的几个编入索引,使该网站看起来有数千页。
除了尝试清理站点、修复安全问题以及让 google 尝试从索引中删除这些页面之外。我想将这些页面重定向到主页本身,因此它完全从 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 开头的页面重定向到我的主页?
你可以试试这个:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} ^index.php
RewriteRule ^(.*)$ http://domain.com/? [R=301,L]
</IfModule>
只有以 "index.php" 开头的查询字符串才会被删除。
此外,上面的代码片段将重定向到您想要访问的任何页面。
如果您希望任何具有以 "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)
对于我的一个网站,google 开始索引如下页面:
www.domain.com/?index.php=en-id1&itemid=3711&view=21
他们在一天之内就将其中的几个编入索引,使该网站看起来有数千页。
除了尝试清理站点、修复安全问题以及让 google 尝试从索引中删除这些页面之外。我想将这些页面重定向到主页本身,因此它完全从 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 开头的页面重定向到我的主页?
你可以试试这个:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} ^index.php
RewriteRule ^(.*)$ http://domain.com/? [R=301,L]
</IfModule>
只有以 "index.php" 开头的查询字符串才会被删除。 此外,上面的代码片段将重定向到您想要访问的任何页面。 如果您希望任何具有以 "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)