The importance of a custom 404 error page is well known and does not need to be rewritten all over again. A familiar, human-readable 404 page seems to be everywhere these days. But I’ve seen a lot of websites not doing it correctly.
A custom 404 error page is supposed to replace the ugly ‘Not Found’ message that browsers show by default for non-existing or mistyped URLs. Such pages can go further than just the pretty notifications by providing options to route users to related pages or by offering search features so that they may find what they are looking for. But all this is for the human user. There is an additional requirement for search engines.
For Apache webservers, the following code redirects requests resulting in 404 errors to a custom 404 error page.
ErrorDocument 404 {path-to-the-custom-404-page}
Now, for search engines, if this is not setup correctly, the resulting page results in a ’200 OK’ status. What this effectively means to the search engines is, whatever URL the user supplied, is taken as a VALID page. The implications can be the search engines indexing that wrong URL. Search Engines indexing a lot of such wrong URLs for your site may have negative results. Instead of an error page, some people try to guess and redirect them directly to a related landing page. This can raise duplicate-content issues. Furthermore, if they are setup to redirect to the home page, it can get pretty ugly.
First thing, as a best practice, is to redirect them to a page which mentions that the URL does not exist and keeps them from bouncing off by providing related links, search features etc.
Second, you should make sure that the {path-to-the-custom-404-page} is not an absolute URL because this can sometimes result in a 200 OK status.
Third, you should make sure that your custom 404 page really returns a 404 status code. In PHP, you can achieve this by simply adding following lines to the top of your custom 404 page.
header("HTTP/1.1 404 Not Found");
header("Status: 404 Not Found");
You can quickly check below to see if your custom error page is correctly returning a 404 status.