簡體   English   中英

RedirectMatch 301 刪除查詢字符串 / URL 參數

[英]RedirectMatch 301 remove query string / URL Parameters

我需要解決 google 搜索控制台錯誤鏈接和 RedirectMatch 301 刪除查詢字符串 / URL 參數在我的 htaccess 中:

谷歌搜索控制台鏈接:

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]

您可以使用以下通用規則刪除查詢字符串

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]

在此處添加另一種 htaccess 規則方法,按照所示示例編寫。 在這里使用 Apache 的THE_REQUEST變量。

確保在測試 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]

暫無
暫無

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

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