首页 > 解决方案 > HTTP_REFERER 中应该和不应该包含(或应该转义)哪些字符?

问题描述

我想用一些新的推荐重写来更新我的 .htaccess 文件,并在 GitHub https://gist.github.com/raniajal/e6733427207de2677616#file-htaccess-txt-L72中找到了一个很好的列表。

我有一种混合格式,我在其他地方找到了转义连字符和非转义连字符;.com、.org、.net、.ga、.ru 等结尾处的斜线,有些没有结尾斜线,例如:

RewriteCond %{HTTP_REFERER} ^http://.*\.social\-buttons\.com/ [NC,OR]
RewriteCond %{HTTP_REFERER} free-share-buttons\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://.*yapoga\.com/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^https?://([^.]+\.)*seoanalyses\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://.*savetubevideo\.com/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://.*semalt\.com/ [NC,OR]
RewriteCond %{HTTP_REFERER} 4webmasters\.org/ [NC,OR]
RewriteCond %{HTTP_REFERER} 7makemoneyonline\.com/ [NC,OR]
RewriteCond %{HTTP_REFERER} 100dollars-seo\.com/ [NC,OR]
RewriteCond %{HTTP_REFERER} addons\.mozilla\.org [NC,OR]
RewriteCond %{HTTP_REFERER} o\-o\-6\-o\-o\.com [NC,OR]
RewriteCond %{HTTP_REFERER} youporn-forum\.ga/ [NC,OR]
RewriteCond %{HTTP_REFERER} непереводимая\.рф/ [NC]

我注意到 GitHub 中的列表没有结尾斜杠,并且更新了符号以允许 https 而我现有的没有,所以我更新了我的列表以使用它。例如:

RewriteCond %{HTTP_REFERER} ^https?:\/\/([^.]+\.)*o-o-6-o-o\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^https?:\/\/([^.]+\.)*slftsdybbg\.ru [NC,OR]
RewriteCond %{HTTP_REFERER} ^https?:\/\/([^.]+\.)*social-buttons\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^https?:\/\/([^.]+\.)*socialseet\.ru [NC,OR]
RewriteCond %{HTTP_REFERER} ^https?:\/\/([^.]+\.)*trafficmonetize\.org [NC,OR]
RewriteCond %{HTTP_REFERER} ^https?:\/\/([^.]+\.)*video--production\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^https?:\/\/([^.]+\.)*videos-for-your-business\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^https?:\/\/([^.]+\.)*vodkoved\.ru [NC,OR]
RewriteCond %{HTTP_REFERER} ^https?:\/\/([^.]+\.)*www1\.social-buttons\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^https?:\/\/([^.]+\.)*ykecwqlixx\.ru [NC,OR]
RewriteCond %{HTTP_REFERER} ^https?:\/\/([^.]+\.)*youporn-forum\.ga [NC,OR]
RewriteCond %{HTTP_REFERER} forum\.topic65882328\.darodar\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^https?:\/\/([^.]+\.)*непереводимая\.рф [NC]

但现在我收到 500 服务器错误,错误日志说

RewriteCond:错误的标志分隔符

该文件是 UTF-8,我没有看到任何多余的空格。我究竟做错了什么?

标签: mod-rewriteescapingcharacterdelimiterhttp-referer

解决方案


这解决了。两个例子的结果似乎没有区别。我重新重新阅读了我的 HTTP_REFERER 项目列表,发现了两个导致问题的项目。列表中间的一个只有 [NC],所以我将其更改为 [NC,OR]。一个缺少 [NC,OR] 所以我添加了那个。

在一个长长的列表中,很容易跳过看起来相同的东西——需要更好的校对。现在 .htaccess 文件可以工作了。


推荐阅读