Share via:

HTTP 404 Not Found

The HTTP 404 status code indicates that the requested resource could not be found.

512 views

Edited: 2019-10-13 04:08

Servers deliver a HTTP 404 Not Found header response when a requested resource is not found, or when it has been deleted. The response will look like this:

HTTP 404 Not Found

The 404 response code is often sent with a message body in HTML containing a error message describing what went wrong to the user.

A good error page will both describe the problem, and show some alternative features or content to the user. This can be in the form of a search box or alternative content suggestions.

To deliver a 404 from PHP, we can use this code:

header(“HTTP 404 Not Found”);
echo 'The resource was not found on this server.'; // A message to the browser

From PHP 5.4 and up you should use:

http_response_code(404);
echo 'The resource was not found on this server.'; // A message to the browser

Problems with 404 error pages

It's important that the correct header status code is delivered, along with the error page itself – as there is no reliable alternative method in the HTML. So-called soft 404 errors will not work.

A custom error page must be larger than 512 bytes to avoid problems with certain browsers and plugins. Otherwise, your page might be replaced with a default error build into the browser.

404 or 301 redirect to homepage

There is some debate in the SEO community as to whether you should redirect deleted pages to the homepage, or leave them deleted, which should produce a 404 error message.

Generally, it does not make sense to redirect deleted content, because users do not expect to be pushed silently around without any explanation as to what happened. It also has little or no affect on SEO, despite the rumors in the community. Reported negative effects are more likely to be other factors, such as having little or no content on the product pages of a webshop. For these reasons, I do NOT recommend you redirect deleted pages.

However, there are circumstances where you may want to show users to a different page, explaining that the content was deleted. Such a page could also show the user related or similar content to what they were requesting. Keep in mind, it would be semantically incorrect to use a 301 redirect for this purpose. Instead, you should correctly output a 404 response code.

Whether your CMS has this functionality already implemented is another matter.

Even if the page you are deleting has a lot of incoming links, you should still delete it. Outside factors, such as the number of incoming links, should not measure into your considerations. It should purely be a technical question relating to your CMS.

See also

  1. Creating a Custom Error Page – How to create a custom error page
  2. HTTP Response Codes – A list of HTTP Response Codes
  3. PHP Header – How to deliver status codes with PHP

Comments