In .htaccess prescribed:

ErrorDocument 404 /views/error.html 

In the script I send the title:

 header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found', true, 404); exit(); 

Redirection does not work. I tried and write:

 header('HTTP/1.1 404 Not Found', true, 404); header('HTTP/1.0 404 Not Found', true, 404); header('HTTP/1.1 404 Not Found'); header('HTTP/1.0 404 Not Found'); 

Doesn't work anyway. Maybe you need to add something else?

1 answer 1

ErrorDocument works correctly when there is really no page. Personally, the transfer of the header also worked correctly for me, and in general, it should work correctly if the server and php are correctly configured. But at the same time, apache is not going to do any redirection in the second paragraph, because it doesn’t see the point - ErrorDocument works precisely because of the actual absence of a page or the absence of redirection rules for the requested address, when the page simply gives 404 code her business. Further it is meant that it is necessary to deduce most necessary.

That is, either to completely enclose a page that lies along the path /views/error.html with something like this:

 if (we_have_404) { header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found', true, 404); include "/views/error.html"; exit(); } 

in order to minimize the duplicate code on the site, or display something of their own.

  • one
    Written logically) I understood. Thank you) - azhirov1991
  • @ azhirov1991 aha. There is another option with Location in the script header - it will redirect to views/error.html , but this will be more than waiting for the visitor, since then we will first have a response from the server with code 302 , after which it will fall on error page. At the same time, by the way, in the error page, the first thing to do is to display the heading 404 , as it receives it automatically only if we hit it using the ErrorDocument server ErrorDocument - Stanislav Belichenko