Apache mod_rewrite 使用 WordPress 阻止 HTTP OPTIONS 请求

Apache mod_rewrite to block HTTP OPTIONS requests, with WordPress

我的 .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>

这里的最佳答案是:

但是,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 规则组合成多种组合。我要么得到 500s,要么 WordPress 网站工作正常并且 OPTIONS 请求得到尊重。

我怎样才能让 WordPress 网站正常工作,同时对 HTTP OPTIONS 请求发出拒绝响应?

我发现通过在 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]