我有一个外部反向链接错误链接到我的网站。
他们将/%E2%80%8E添加到链接的末尾,因此它将以http://mywebsite.com/%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]
谢谢
如果不想使用解码后的字符串,可以使用'x##
。解码字符串工作的原因是,在RewriteRule
's中,URI在应用模式之前被解码。
RewriteRule ^'xE2'x80'x8E$ / [L,R=301]
在你的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重写稍微好一点,因为它不需要你在服务器上启用mod_rewrite模块。