htaccess将编码的网址重定向到主页

时间:2014-03-18 23:49:49

标签: php apache .htaccess redirect

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

他们正在链接的末尾添加/%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]

由于

3 个答案:

答案 0 :(得分:2)

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

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

答案 1 :(得分:0)

在你的htaccess中尝试一下。

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

答案 2 :(得分:0)

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

在我看来,这个方法比mod重写略好,因为它不需要你在服务器上启用mod_rewrite模块。

相关问题