如何用.htaccess忽略URL中无?的Google追踪参数避免404错误
解决Google追踪参数因缺失
?被识别为路径导致的404问题 我的URL类似 site.com/postname&sa=U&ved=2ahdff1kkkmoECAgQAg&usg=AOvVaw0ayMEVIHqWpMNVGcZRwNcA,这类Google转化追踪参数因为缺少?,未被识别为查询字符串,反而被当作路径的一部分,导致返回404错误。
我尝试了以下多条.htaccess规则,均无效:
无效规则示例
- 规则1:
<IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^&sa=U&ved=(.*)$ /$1 [R=301,L] </IfModule>
- 规则2:
<IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^&sa=U&ved=(.*)$ /$1 [QSA,L] </IfModule>
- 规则3:
<IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^&sa\=U&ved\=(.*)$ /$1 [R=301,L] </IfModule>
- 规则4:
<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{THE_REQUEST} ^&sa=U&ved=(.*) RewriteRule .* https://%{SERVER_NAME}/$0 [R=301,L] </IfModule>
更新:可处理参数但会触发301重定向的规则
我找到一条能处理这类参数的规则,但它会触发301重定向,改变原本的URL:
<IfModule mod_rewrite.c> RewriteEngine On RewriteRule (.*)&sa\=U&ved\=(.*)$ https://%{SERVER_NAME}/$1? [QSA,L] </IfModule>
需求
我需要保持URL不变,仅忽略这些多余的追踪参数,让页面正常显示site.com/postname的内容。此前尝试使用[P]标志,触发了500错误。
内容的提问来源于stack exchange,提问作者Val
相关产品推荐
相关产品推荐

