【发布时间】:2013-08-11 16:13:24
【问题描述】:
如果访问者来自某些通过 .htaccess (Apache) 的引用者,我会尝试阻止他们。
在网络上的多个地方发现了此代码和变体,但它似乎阻止了所有流量,而不仅仅是引用域:
# block visitors referred from indicated domains
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_REFERER} sweetfreestuff.com [NC,OR]
RewriteCond %{HTTP_REFERER} wormhole.com [NC,OR]
RewriteRule .* - [F]
</ifModule>
也尝试过这种变化,没有任何变化:
# block visitors referred from indicated domains
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_REFERER} sweetfreestuff\.com [NC,OR]
RewriteCond %{HTTP_REFERER} wormhole\.com [NC,OR]
RewriteRule .* - [F]
</ifModule>
【问题讨论】:
-
.com 之前不需要反斜杠吗? (javascriptkit.com/howto/htaccess14.shtml) 我想我从来没有尝试过没有... 和 RewriteCond 之前的 # Options +FollowSymlinks?
-
我试过有无斜线。
-
嗯,如果您收到 500 错误,请尝试评论 +FollowSyslinks。并确保
-
@lostphilosopher +FollowSyslinks 是否存在并没有任何区别。我也尝试过不使用 IfModule。仍然没有运气。我最终采用了一种稍微冗长的方式。请参阅下面的答案。
标签: .htaccess http-referer referer