簡體   English   中英

htaccess將查詢字符串重定向到主頁

[英]htaccess redirect query string to homepage

對於我的一個網站,谷歌開始索引頁面,如:

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開頭的網頁重定向到我的主頁?

你可以試試這個:

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

只有以“index.php”開頭的查詢字符串才會被刪除。 此外,上面的代碼段會重定向到您要去的任何頁面。 如果您希望任何以“index.php”開頭的查詢請求始終重定向到主頁。 您可以進行以下調整:

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

額外資源:

htaccess 301 redirect - 刪除查詢字符串(QSA)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM