【发布时间】:2022-01-22 20:28:41
【问题描述】:
我需要解决 google 搜索控制台错误链接和 RedirectMatch 301 删除我的 htaccess 中的查询字符串/URL 参数:
Google Search Console 链接:
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]
【问题讨论】:
-
RedirectMatch 和 RewriteRule 都只匹配 URL 的 path 组件。并且您的 RewriteCond 尝试匹配由 only
main_page组成的查询字符串。 -
啊好吧,正确的方法是什么?
-
如果您只想在任何地方匹配任何包含
main_page的查询字符串 - 然后不要在开始和结束处锚定 RewriteCond 模式。而在 RewriteRule 中仅匹配根的路径将只是一个空路径,所以^$
标签: apache .htaccess redirect mod-rewrite query-string