我需要針對 google 搜索控制臺錯誤鏈接和 RedirectMatch 301 洗掉我的 htaccess 中的查詢字串/URL 引數的解決方案:
谷歌搜索控制臺鏈接:
https://www.domain.de/?main_page=index&zenid=umf5etlrmr4blnuiq0e4jsp6l2&cPath=15_326&sort=20a&alpha_filter_id=68
https://www.domain.de/index.php?main_page=product_reviews_write&products_id=9985&cPath=5_380&number_of_uploads=0
https://www.domain.de/?main_page=index&cPath=46_47&sort=20a&alpha_filter_id=70
https://www.domain.de/?currency=USD&main_page=products_new&disp_order=7&page=141
https://www.domain.de/?main_page=index&zenid=mj6nsb9r53goiu6e13nb80tfq7&cPath=1_160&sort=20a&alpha_filter_id=70
https://www.domain.de/?currency=USD&main_page=index&cPath=3_137
https://www.domain.de/?main_page=index&cPath=46_76&sort=20a&alpha_filter_id=84
https://www.domain.de/?main_page=index&cPath=5_6&sort=20a&alpha_filter_id=85
https://www.domain.de/index.php?main_page=index
還有很多。
我在 htaccess 中以這種方式進行了測驗,但沒有奏效:
RedirectMatch 301 ^/?main_page*$ https://www.domain.de/
RedirectMatch 301 ^/?main_page\=$ https://www.domain.de/
RewriteEngine on
RewriteCond %{QUERY_STRING} ^main_page$ [NC]
RewriteRule ^/?main_page?$ https://www.domain.de/ [L,R=301]
uj5u.com熱心網友回復:
您可以使用以下通用規則來洗掉查詢字串
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(main_page|currency) [NC]
RewriteCond %{REQUEST_URI} ^/$ [OR]
RewriteCond %{REQUEST_URI} ^/index\.php$ [NC]
RewriteRule ^ %{REQUEST_URI}? [L,R=301]
uj5u.com熱心網友回復:
在此處添加另一種 htaccess 規則方法,按照所示示例撰寫。THE_REQUEST在這里使用 Apache 的變數。
確保在測驗 URL 之前清除瀏覽器快取。
RewriteEngine ON
RewriteCond %{THE_REQUEST} \s/(?:index\.php)?/?(?:\?(?:main_page|currency))?\s [NC]
RewriteRule ^ %{REQUEST_URI}? [L,R=301]
或作為替代使用以下代碼(QSD在此處使用標志來洗掉查詢字串):
RewriteEngine ON
RewriteCond %{THE_REQUEST} \s/(?:index\.php)?/?(?:\?(?:main_page|currency))?\s [NC]
RewriteRule ^ %{REQUEST_URI} [L,R=301,QSD]
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/389251.html
上一篇:在創建串列時使用case陳述句
