【发布时间】:2014-05-22 21:58:02
【问题描述】:
我在 htaccess 中使用以下内容:
ErrorDocument 400 /core/php/error.php
ErrorDocument 401 /core/php/error.php
ErrorDocument 403 /core/php/error.php
ErrorDocument 404 /core/php/error.php
ErrorDocument 500 /core/php/error.php
ErrorDocument 502 /core/php/error.php
ErrorDocument 504 /core/php/error.php
error.php 看起来像这样:
switch($_SERVER["REDIRECT_STATUS"]){
case 400:
xxxxxxxxx relevant code here
break;
case 403:
xxxxx code here
break;
...
我想确切地知道导致 404 错误的资源是什么(将它们放在这样的数组中:
$array[err01][image.jpg]
[err02][file.html]
并且还想知道导致 403 错误的确切 url,如下所示:
$array[referer][here goes the referer, if it exists]
[403 error route][user tried to access: public/admin/core/php]
可以吗?如果是这样,如何?!!! 在这上面浪费了一整天,仍然没有! (真是个菜鸟!)
【问题讨论】:
-
应该有另一个 $_SERVER 值具有原始请求的 URL,即触发错误的那个。做一个
var_dump($_SERVER)并挖掘输出。我不记得它的名字是什么,但它会是“HTTP_ORIGINAL_REQUEST”或类似的东西。 -
谢谢,成功了,$_SERVER 的值是 REQUEST_URI
标签: php apache .htaccess error-handling