【问题标题】:Blocking Visitors Referred From Indicated Domains阻止来自指定域的访问者
【发布时间】: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


【解决方案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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-21
    • 1970-01-01
    • 2018-03-12
    • 2012-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-30
    相关资源
    最近更新 更多