0
votes

I'm using .htaccess file to redirect to error pages if error occured but error not found. I'm test if the error.php pages are working but the following result I got. The 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

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

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
2

2 Answers

0
votes

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.

Check the log files of Apache to see other errors.

It seems it's not your problem but you need to set correctly the AllowOverride.

Check if the directory on the Apache configuration has something like

AllowOverride none

If yes, you should change it to allow the .htaccess files override some configurations. The ErrorDocument directive needs FileInfo or All like this:

AllowOverride FileInfo
0
votes

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.

Check the log files of Apache to see other errors.

It seems it's not your problem but you need to set correctly the AllowOverride.

Check if the directory on the Apache configuration has something like