Sending 404 page not found error and then redirecting with header location doesn’t work

The problem with this is that what is actually generated and sent to the browser in the http headers is a “temporarily moved” status (HTTP/1.x 302 OK) and not a 404 “page not working” error code. found”.

This happens because the header (“location: /error.php?cod=3”); overwrites the 404 error that was previously sent.

Therefore, it means that you are not actually sending the error correctly. The problem with this is not because of the site visitors, who are going to see that the content they were looking for could not be found. The problem is for search engines, who will understand that a page that doesn’t really exist has been temporarily moved to a new URL. So it looks like we have URLs that don’t really exist.

The way to fix it is to not do the redirection header(“location:…”); after generating the 404 error code.

To do this you can simply write the error description directly on the page. If you have the code that describes an error on another page, then simply include that file with a PHP include.

header(“HTTP/1.0 404 Not Found”);
header(“Status: 404 Not Found”);
include(“error.php”);

See also  JSON
Loading Facebook Comments ...
Loading Disqus Comments ...