简体   繁体   English

htaccess:尝试 ErrorDocument 时出现 404 Not Found 错误

[英]htaccess: 404 Not Found Error While trying ErrorDocument

I'm using .htaccess file to redirect to error pages if error occured but error not found.如果发生错误但未找到错误,我正在使用 .htaccess 文件重定向到错误页面。 I'm test if the error.php pages are working but the following result I got.我正在测试 error.php 页面是否正常工作,但我得到了以下结果。 The 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.尝试使用 ErrorDocument 处理请求时遇到 404 Not Found 错误。

.htaccess .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

<?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;
}
?>

Result:结果:

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

You're redirecting to the root (/error.php) of the DocumentRoot of the selected virtualhost, check if the error.php it's on that DocumentRoot.您正在重定向到所选虚拟主机的 DocumentRoot 的根目录(/error.php),检查 error.php 是否在该 DocumentRoot 上。

Check the log files of Apache to see other errors.检查 Apache 的日志文件以查看其他错误。

It seems it's not your problem but you need to set correctly the AllowOverride.看来这不是您的问题,但您需要正确设置 AllowOverride。

Check if the directory on the Apache configuration has something like检查Apache配置上的目录是否有类似的东西

AllowOverride none

If yes, you should change it to allow the .htaccess files override some configurations.如果是,您应该更改它以允许 .htaccess 文件覆盖某些配置。 The ErrorDocument directive needs FileInfo or All like this: ErrorDocument 指令需要FileInfoAll ,如下所示:

AllowOverride FileInfo

You're redirecting to the root (/error.php) of the DocumentRoot of the selected virtualhost, check if the error.php it's on that DocumentRoot.您正在重定向到所选虚拟主机的 DocumentRoot 的根目录 (/error.php),检查 error.php 是否在该 DocumentRoot 上。

Check the log files of Apache to see other errors.检查 Apache 的日志文件以查看其他错误。

It seems it's not your problem but you need to set correctly the AllowOverride.看来这不是您的问题,但您需要正确设置 AllowOverride。

Check if the directory on the Apache configuration has something like检查Apache配置上的目录是否有类似的东西

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试使用 ErrorDocument 处理请求时遇到 404 Not Found 错误 - A 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request 尝试使用ErrorDocument时出现404 Not Found错误 - Getting 404 Not Found error while trying to use ErrorDocument 在 codeigniter 中出错:尝试使用 ErrorDocument 处理请求时遇到 404 Not Found 错误 - Getting error in codeigniter : a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request drupal内部服务器错误。 此外,尝试使用ErrorDocument处理请求时遇到404 Not Found错误。 - drupal internal server error. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request Codeigniter ,尝试使用 ErrorDocument 处理请求时遇到 404 Not Found 错误 - Codeigniter , 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request 使用.htaccess时出现404 Not Found错误 - 404 Not Found error while using .htaccess htaccess ErrorDocument 404重定向不起作用 - htaccess ErrorDocument 404 redirect not working ErrorDocument 404 .htaccess 不能与 RewriteRule 一起使用 - ErrorDocument 404 .htaccess not working with RewriteRule htaccess错误文档404并将URL传递到路径 - htaccess errordocument 404 and pass url to path .htaccess ErrorDocument 404不要打开页面 - .htaccess ErrorDocument 404 dont open the page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM