0

如果访问者来自某些通过 .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>
4

1 回答 1

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
于 2013-08-09T17:49:41.403 回答