我正在使用.htaccess文件重定向到错误页面,如果发生错误但没有找到错误。我正在测试error.php页面是否正常工作,但我得到了以下结果。尝试使用ErrorDocument处理请求时遇到404 Not Found错误。
.htaccess
RewriteEngine On
ErrorDocument 400 /error.php
ErrorDocument 401 /error.php
ErrorDocument 403 /error.php
ErrorDocument 404 /error.php
ErrorDocument 500 /error.php
ErrorDocument 502 /error.php
ErrorDocument 504 /error.php
error.php
<?php
switch($_SERVER["REDIRECT_STATUS"]){
case 400:
$title = "400 Bad Request";
$description = "The request can not be processed due to bad syntax";
break;
case 401:
$title = "401 Unauthorized";
$description = "The request has failed authentication";
break;
case 403:
$title = "403 Forbidden";
$description = "The server refuses to response to the request";
break;
case 404:
$title = "404 Not Found";
$description = "The resource requested can not be found.";
break;
case 500:
$title = "500 Internal Server Error";
$description = "There was an error which doesn't fit any other error message";
break;
case 502:
$title = "502 Bad Gateway";
$description = "The server was acting as a proxy and received a bad request.";
break;
case 504:
$title = "504 Gateway Timeout";
$description = "The server was acting as a proxy and the request timed out.";
break;
}
?>
结果:
Not Found
The requested URL /myweb/faq.html was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Apache/2.4.23 (Win32) OpenSSL/1.0.2h PHP/7.0.13 Server at 192.168.5.120 Port 80
发布于 2017-05-19 15:42:00
您正在将重定向到所选虚拟主机的的根DocumentRoot (/error.php),请检查该error.php是否在该DocumentRoot上。
查看Apache的日志文件,查看其他错误。
这似乎不是你的问题,但你需要正确设置AllowOverride。
检查Apache配置上的目录是否包含以下内容
AllowOverride none
如果是,则应将其更改为允许.htaccess文件覆盖某些配置。ErrorDocument指令需要FileInfo或类似下面的所有内容:
AllowOverride FileInfo
发布于 2020-04-02 21:41:03
您正在重定向到所选虚拟主机的DocumentRoot的根目录(/error.php),请检查error.php是否在该DocumentRoot上。
查看Apache的日志文件,查看其他错误。
这似乎不是你的问题,但你需要正确设置AllowOverride。
检查Apache配置上的目录是否包含以下内容
https://stackoverflow.com/questions/44060673
复制相似问题