使用Apache对HTTP 404不在URI白名单中的每个请求进行响应

时间:2019-07-02 03:57:53

标签: wordpress apache mod-rewrite http-status-code-404

如果请求URI与我的白名单中的内容不匹配,我试图重定向到静态404.html页面。现在只是/golf,以保持简单。

这是我的Apache vhosts配置:

<VirtualHost _default_:443>

DocumentRoot "/var/www/crmpicco/wordpress"
ServerName crmpicco.localhost:443
ServerAlias www.crmpicco.localhost
ServerAdmin crmpicco@crmpicco.co.uk
ErrorLog "/private/var/log/apache2/crmpicco.localhost.error_log"
TransferLog "/private/var/log/apache2/crmpicco.localhost.access_log"
ErrorDocument 404 404.html

<Directory "/var/www/crmpicco/wordpress/">
        Options +FollowSymLinks
        DirectoryIndex index.php
        Options -Indexes
        Require all granted
        AllowOverride all

        RewriteEngine On
        RewriteCond %{REQUEST_URI} !^/golf
        RewriteRule ^ - [R=404,L]
</Directory>

我已加载mod_rewrite Apache模块,并且在添加RewriteRule之后当然已经重启了Apache。

我想念什么?目前,它只是命中主题中的404脚本,该脚本由Wordpress处理,而不是由Apache处理。

编辑:尝试找出根本原因。

当我在机器上寻找httpd-ssl.conf时,会得到多份副本。

$ locate httpd-ssl.conf
/private/etc/apache2/extra/httpd-ssl.conf
/private/etc/apache2/extra/httpd-ssl.conf.mojave
/private/etc/apache2/original/extra/httpd-ssl.conf
/usr/local/Cellar/httpd/2.4.35/.bottle/etc/httpd/extra/httpd-ssl.conf
/usr/local/Cellar/httpd/2.4.35/.bottle/etc/httpd/original/extra/httpd-ssl.conf
/usr/local/etc/httpd/extra/httpd-ssl.conf
/usr/local/etc/httpd/original/extra/httpd-ssl.conf

apachectl似乎指向未使用的配置!

$ apachectl -S
VirtualHost configuration:
*:443                  crmpicco.localhost (/usr/local/etc/httpd/extra/httpd-ssl.conf:121)
ServerRoot: "/usr/local/opt/httpd"
Main DocumentRoot: "/var/www"
Main ErrorLog: "/usr/local/var/log/httpd/error_log"
Mutex ssl-stapling: using_defaults
Mutex ssl-cache: using_defaults
Mutex default: dir="/usr/local/var/run/httpd/" mechanism=default 
Mutex mpm-accept: using_defaults
Mutex ssl-stapling-refresh: using_defaults
Mutex rewrite-map: using_defaults
PidFile: "/usr/local/var/run/httpd/httpd.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="_www" id=70 not_used
Group: name="_www" id=70 not_used

/usr/local/etc/httpd/extra/httpd-ssl.conf文件是我上面一直在编辑以添加RewriteRules的配置文件,但是这似乎没有任何作用。

我注意到,当我禁用/private/etc/apache2/extra/httpd-ssl.conf文件时,它将破坏我的Apache配置,并且页面无法加载,因此看起来好像是正在使用的文件-但是apachectl为什么报告了不同的内容文件?!

0 个答案:

没有答案