阻止来自指示域的访问者

时间:2013-08-09 16:40:07

标签: .htaccess http-referer referer

我试图阻止访问者,如果他们来自某些引用来自.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>

1 个答案:

答案 0 :(得分:1)

找到另一条路线..仍然是.htaccess,但是一种不同的语法将引用者的测试与引用者的禁止分开。

# Deny access to all with status "banned"
SetEnvIfNoCase Referer "^http://([a-z0-9\-]+\.)?sweetfreestuff\.com.*$" banned

# Enable Rewrite mode
Options +FollowSymlinks
RewriteEngine On

# 301-Redirect to themselves
RewriteCond %{ENV:banned} ^1$
RewriteCond %{HTTP_REFERER} ^(.*)$

# In any case => 403-Forbidden Page
Order Deny,Allow
Deny from env=banned