【问题标题】:Apache mod_rewrite to block HTTP OPTIONS requests, with WordPressApache mod_rewrite 使用 WordPress 阻止 HTTP OPTIONS 请求
【发布时间】:2021-06-08 18:09:54
【问题描述】:

我的 .htaccess 中有一个有效的 mod_rewrite cond/rule 可以完美地停止 HTTP OPTIONS 请求。

RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^OPTIONS
RewriteRule .* - [F]

我也有 Apache 配置(用于腰带和大括号):

<Location />
    <LimitExcept GET POST>
        order deny,allow
        deny from all
    </LimitExcept>
</Location>

正如这里的最佳答案所建议的那样:Disable OPTIONS HTTP on Apache Server

然而,WordPress 将以下内容添加到同一个 .htaccess 文件中:

# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php 
</IfModule>
# END WordPress

这样做会杀死我的 HTTP OPTIONS 杀手,这可以在对此请求的响应中看到:

> curl -i -X OPTIONS https://www.MYWEBSITE.co.uk/

HTTP/1.1 302 Found
Server: Apache
X-Redirect-By: WordPress
....

我尝试将这两个 mod_rewrite 规则组合成多种组合。我要么得到 500,要么 WordPress 网站运行良好并且 OPTIONS 请求得到尊重。

如何让 WordPress 网站正常工作,同时对 HTTP OPTIONS 请求发出拒绝响应?

【问题讨论】:

    标签: wordpress mod-rewrite


    【解决方案1】:

    我发现通过在 WordPress HTACCESS 指令上方添加以下内容可以解决问题:

    RewriteEngine on
    RewriteCond %{THE_REQUEST} !^(POST|GET)\ /.*\ HTTP/1\.1$
    RewriteRule .* - [F]
    

    我在这里找到了这个建议: https://protonts.wordpress.com/2013/08/15/how-to-disable-http-options-method/

    现阶段我不清楚为什么上面的方法有效,而下面的方法没有起作用:

    RewriteEngine On
    RewriteCond %{REQUEST_METHOD} ^OPTIONS
    RewriteRule .* - [F]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-09
      • 2019-09-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-05
      相关资源
      最近更新 更多