【问题标题】:Apache 2.4 Block Requests Without User-Agent没有用户代理的 Apache 2.4 阻止请求
【发布时间】:2020-12-29 19:14:11
【问题描述】:

我的目标是简单地阻止没有设置 User-Agent 标头的请求。来自Apache's docs,这应该很简单。我一直在尝试使用(在 VirtualHost 部分)如下:

RewriteEngine on
RewriteCond ${HTTP_USER_AGENT} ^$    
RewriteRule .* - [F]

我正在使用curl 使用以下内容(更改了域名)对此进行测试:

curl -v --http1.1 https://example.com/ > /dev/null

为此发送的标头是:

> GET / HTTP/1.1
> Host: example.com
> User-Agent: curl/7.68.0
> Accept: */*

curl -v --http1.1 --user-agent "" https://example.com/ > /dev/null

而为此发送的标头是:

> GET / HTTP/1.1
> Host: example.com
> Accept: */*

在这两种情况下,我都看到了我希望看到的发送内容。

无论我做什么,Apache 都会很高兴地为两者返回 200。我在这里错过了什么?

【问题讨论】:

    标签: apache mod-rewrite user-agent


    【解决方案1】:

    您快到了,Apache 服务器变量的前缀是 %,而不是 $

    RewriteEngine on
    RewriteCond %{HTTP_USER_AGENT} ^$    
    RewriteRule .* - [F]
    

    【讨论】:

      猜你喜欢
      • 2018-12-14
      • 1970-01-01
      • 1970-01-01
      • 2019-05-02
      • 1970-01-01
      • 2019-01-29
      • 2016-01-02
      • 1970-01-01
      相关资源
      最近更新 更多