【发布时间】:2016-11-30 19:32:23
【问题描述】:
我试图弄清楚为什么 Apache 不将 ErrorDocument 路径作为 PHP $_SERVER 变量传递。
采用以下 Apache VHOST 配置。所有请求都发送到“index.php”,除非请求在“/js”、“/media”或“/skin”中(很像 Magento)。
# Error documents
ErrorDocument 401 /core/error/notauthorized/
ErrorDocument 403 /core/error/notfound/
ErrorDocument 404 /core/error/notfound/
ErrorDocument 500 /core/error/internalservererror/
ErrorDocument 503 /core/error/serviceunavailable/
# index.php rewrite bootstrap
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}$1 [R=301,L]
RewriteCond %{REQUEST_URI} !^/(js|media|skin)/
RewriteRule .* /var/www/mydomain.com/public/www/index.php [L]
假设用户尝试访问“/skin”目录中不存在的文件:“/skin/i/dont/exist.jpg”。
我的期望是,由于 Apache 发现此文件在物理上不存在,它会尝试(与根相关)向“/var/www/mydomain.com/public/www/core/error/notfound/ ”。它确实这样做了,并且通过引导程序正确处理了请求。但是,所有 $_SERVER 变量都表示最初请求的路径“/skin/i/dont/exist.jpg”,而不是 ErrorDocument 路径。
Apache 确实将“REDIRECT_STATUS”设置为 404,但似乎这是我知道存在问题的唯一方法。我希望我的引导程序 index.php 知道 Apache 实际上是在尝试请求“/core/error/notfound/”,因此它的路由正确。
我是否缺少 Apache 设置?我对这应该如何运作的期望是否不正确?我在 Ubuntu 上使用 PHP 7.0.8 和 Apache 2.4.18。
【问题讨论】: