【问题标题】:Denying access to URLs then IP blocks in htaccess拒绝访问 URL,然后在 htaccess 中阻止 IP
【发布时间】:2016-06-23 04:31:29
【问题描述】:

我正试图阻止恶意机器人点击某些链接到一个运行 Apache 2.4 的站点。这是我在htaccess 中尝试的内容:

RewriteEngine On

# Check for the suspect querystring first
RewriteCond %{QUERY_STRING} gclid=(.*)
RewriteRule .* - [E=IsAdClick:1]

# Filter on those requests with an ad string
<IfDefine IsAdClick>

    # BAN USER BY IP
    Order Deny,Allow
    Deny from 172.64.0.0/13
    Deny from 173.245.48.0/20
    ...

</IfDefine>

如果拒绝规则单独使用,则它们会起作用,但是对于我的一生,我无法使条件起作用。我尝试过其他方法,例如

<If "%{QUERY_STRING} =~ /gclid=.*?/">

     # BAN USER BY IP
    Order Deny,Allow
    Deny from 172.64.0.0/13
    Deny from 173.245.48.0/20
    ...

</If>

但是没有效果。流量仍然通过。我错过了什么?我不想为每个 IP 写一大堆RewriteCond,也不想更改.config 文件。谢谢。

更新: 根据this SO post 看来IfDefine 只响应命令行参数。参考:

Apache 中的 IfDefine 指令, Only , ONLY 以及当我说 only i 仅表示,响应在命令行传递的参数。让我来 强调一点。只有命令行!

但是如何达到我想要的效果呢?

【问题讨论】:

    标签: apache .htaccess mod-rewrite


    【解决方案1】:

    这需要大量的试验和错误,但这似乎适用于 THE_REQUEST,其中包括任何查询字符串数据:

    # Filter on those requests with an adwords string
    <If "%{THE_REQUEST} =~ /gclid=/i">
    
        # BAN USER BY IP
        Order Deny,Allow
        Deny from 172.64.0.0/13
        Deny from 173.245.48.0/20
        ...    
    </If>
    

    不过,我想知道为什么我的第二次尝试失败了。

    【讨论】:

      猜你喜欢
      • 2017-02-20
      • 1970-01-01
      • 2016-10-22
      • 2021-01-30
      • 2017-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-24
      相关资源
      最近更新 更多