What is and how does a 404 error page work?

It is important to anticipate all possible mistakes that will arise when browsing our websites over time: broken links, programming errors, failure to connect to the database…

To correct most problems properly and professionally, you should generally use the sampling a 404 error html page. In this way, we will not only be notifying the user that something has not gone well, but also, in the face of search engines, we could notify them that a specific url no longer exists.


  • What is 404 page not found?
  • I don’t have a properly configured 404 page. Problems?
  • And what would a successful 404 page look like?
  • How to display 404 error header in php
  • Any questions about configuring the 404 error on your website?

What is 404 page not found?

Surely it has ever happened to you, you have entered a web page and take it! 404 page not found. A summary message usually describes the problem better and in most cases hosting providers accompany the message with an image of Oops! It seems that this page no longer exists.

a page of 404 page not found error It is the message that the user sees when he tries to access a page of a website that does not exist, derived for example by a broken link, because the address to the page has been removed or because he made a mistake when typing the url.

404 pages go by this name because they are the response to requests for pages (their url ) that do not respond. Web servers, by default, send a HTTP status code 404 to warn of a page that no longer exists or presents a problem.

I don’t have a properly configured 404 page. Problems?

  1. easy, simply your potential reader/client/visitor He will leave, you will have lost him of all, with what it costs to get visits and you have lost one due to nonsense!
  2. You could incur a serious mistake in the eyes of search engines (Google and CIA)How is it possible? Well, because there are cases in which it is no longer the provider that shows this page, but a php error has occurred on your website, due to a slip, and your content remains blank or half-assembled. The browser then says: ok this page now has this text (Apache error for example) and the page of the site yoursite.com/page/page2 It now has a completely different indexing than the original.
  3. You may be displaying a custom 404 page but you have not notified the browser or search engines (who are the ones who scare us the most), and we are going to see below how to solve it so that Mr. Google and company stop indexing your 404 page as one more content on the web.

And what would a successful 404 page look like?

The 404 page that should be displayed It should be yours, first of all, a custom page on your site that might even display a message like: This page no longer exists, but you may be interested in visiting these other publications (and show the user other links on the page for example).

A well done 404 page can get a visit from a user who would normally leave the site. So get creative and check out these original 404 page examples.

Design details and positioning aside, a 404 page displayed via php or web should have a header status code 404 before the html code.

How to display 404 error header in php

Before displaying our attractive 404 page in html, it is essential send a header that indicates the exact status code 404 httpd. The function headers from php allows us to send raw httpd headers. It is common to use this header() function to perform 301 redirects or display HTTP status codes.

Remember that to send httpd headers with function headers You must not have sent any kind of screen output, no blank lines, no html, etc.

The correct use code of the function headers to send the 404 header would be the following:

header("HTTP/1.0 404 Not Found");

Include this line of code before displaying your html 404 page and voila, you’re all set!

A more complete example in php for any page, in which a include to display the corresponding view would be:

if($existe == true){
}else{ //error la página ya no existe
     header("HTTP/1.0 404 Not Found");     

This script could belong to a blog page of any site (for example srcodigofuente.com). If a specific publication is not found, I send the http 404 header thanks to the function header() and later I include my custom page 404.php.

Any questions about configuring the 404 error on your website?

If you have come this far, it is because you have read the article, I hope you have found it useful! If so, I would appreciate it if you share it or leave a comment below.

It would also be great if you could tell me about your experience with the start-up or any related questions.

Thank you!

Leave a Reply