Php htaccess将编码的url重定向到主页

Php htaccess将编码的url重定向到主页,php,apache,.htaccess,redirect,Php,Apache,.htaccess,Redirect,我有一个外部反向链接,它错误地链接到我的网站 他们正在将/%E2%80%8E添加到链接的末尾,因此它将作为 我想使用htaccess将这些人重定向到我的主页 这就是我目前拥有的: #This version does not work for some reason RewriteRule %E2%80%8E https://mysite.com [B,R,L] RewriteCond %{QUERY_STRING} %E2%80%8E RewriteRule .? https://mysite

我有一个外部反向链接,它错误地链接到我的网站

他们正在将/%E2%80%8E添加到链接的末尾,因此它将作为

我想使用htaccess将这些人重定向到我的主页

这就是我目前拥有的:

#This version does not work for some reason
RewriteRule %E2%80%8E https://mysite.com [B,R,L]
RewriteCond %{QUERY_STRING} %E2%80%8E
RewriteRule .? https://mysite.com [B,R,L]

# This version works if I type in the DECODED version of the string
RewriteRule ‎ https://mysite.com [R,L]
RewriteCond %{QUERY_STRING} ‎
RewriteRule .? https://mysite.com [R,L]

谢谢

在您的htaccess中尝试一下

RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/%E2%80%8E\s [NC]
RewriteRule ^ https://mysite.com/ [L,R=301]

无需使用.htaccess重写即可解决此问题。在我的一些网站上,我会检查页面的标题(使用PHP或JS)或自定义404页面


在我看来,这种方法比mod rewrite稍微好一点,因为它不需要您在服务器上启用mod#u rewrite模块。

如果您不想使用解码字符串,可以使用
\x#
。解码字符串工作的原因是在重写规则中,URI在应用模式之前被解码

RewriteRule ^\xE2\x80\x8E$ / [L,R=301]