Correctly Return HTTP Status Code 404 for an Error Page - SISTRIX (2024)

From:

SISTRIX Content Team

Steve Paine

27.03.2024

4xx Client Error (404 Error Page)

  • 403 Forbidden: What Does This Status Code Mean?
  • Correctly Return HTTP Status Code 404 for an Error Page
  • How do I return the correct HTTP status code for my 404 error page?
  • What Is Status Code 410?
  • Why should a 404 error page return the correct HTTP status code and not be redirected?
  • Back to overview

A 404 error page, also known as ErrorDocument 404, is primarily a page that informs the user that the requested resource does not exist.

Contents

Contents

  • How do I return the correct HTTP status code 404 for a 404 error page?
  • .htaccess and Apache web server – correctly configuring the error page
  • Setting up an error page in Nginx
  • WordPress CMS – correctly configuring the error page
  • Why is the correct HTTP status code for error pages important?
  • What exactly is a soft 404 error?
  • Our Google conclusion
  • Video Explanation by Matt Cutts / Google on this topic

For example, if a user follows a link whose target page no longer exists, the web server should display a so-called 404 error page.

However, a 404 error page is responsible for far more than this. When configured correctly, it informs the Googlebot about non-existent documents. To ensure that this happens the way it should, it is important that a 404 error page also returns the correct HTTP status code 404.

  • Why should a 404 error page return the correct HTTP status code and not be redirected to the homepage?

How do I return the correct HTTP status code 404 for a 404 error page?

If the web server or the content management system (CMS) used is configured incorrectly so that an error page either returns the HTTP status code 200 (OK) or redirects users & the Googlebot to another page using a 301 redirect, this is referred to as a defective 404 page or a soft 404 error.

In this article, we will discuss the correct configuration of a 404 error page with the appropriate HTTP status code 404. We will differentiate between two use cases:

  • static 404 error page using the Apache web server and the .htaccess file
  • using the CMS WordPress and the existing 404.php file in the theme directory

.htaccess and Apache web server – correctly configuring the error page

Regardless of whether you use .html or .php files for your website or if you stick to a directory structure – a 404 error page is created by entering the following into the .htaccess file:

Correctly Return HTTP Status Code 404 for an Error Page - SISTRIX (2)

The screenshot shows how the relative path to the error document is added to the .htaccess file.

Open or create the .htaccess file and enter the relative path to the error page. You must first create the error page (e.g. 404.html) as a file.

ErrorDocument 404 /404.html

The entire process, step by step:

  • Create an error page (404.html or 404.php) on the first level of the website (root directory).
  • Open the .htaccess file or create one if it does not exist (also in the root directory).
  • Enter “ErrorDocument 404” followed by the relative path to the error page.
  • Save and request a page that does not exist, like http://www.your-domain.com/98899351.
  • You should now see the contents of the error page 404.html.
  • Check if the correct HTTP status code 404 is returned here.
Correctly Return HTTP Status Code 404 for an Error Page - SISTRIX (3)

The non-existent page https://www.sistrix.de/98899351 returns the HTTP status code 404.

Setting up an error page in Nginx

If you use Nginx, you can set up a 404 error page by entering the following in the corresponding server block of the config file:

error_page 404/404.html

The only difference between these steps and those mentioned above is the entry in the config file and the absence of .htaccess. The rest of the workflow also applies here.

WordPress CMS – correctly configuring the error page

If you use the content management system (CMS) WordPress, setting the correct HTTP status code for the 404 error page is easy – provided the theme you use supports it.

Many WordPress themes, designs or templates have a corresponding 404.php file in the respective theme folder. Should you be unable to find this file, set up an error page using .htaccess.

Open the 404.php file in your active WordPress theme and enter the following in the first line:

Correctly Return HTTP Status Code 404 for an Error Page - SISTRIX (4)

Above: Configuring the HTTP status code 404 for a WordPress error page

The error page 404.php can usually be found in the theme directory in /wp-content/themes/active-themename/

<?php header("HTTP/1.0 404 Not Found"); ?>

The entire process, step by step:

  • Find and open the error page in the WordPress theme folder (usually “404.php”).
  • Add the above PHP source code to the first line and save the file.
  • Open a page that does not exist, like http://www.your-domain.com/98899351.
  • You should now see the contents of the error page 404.html.
  • Check if the correct HTTP status code 404 is returned here.
Correctly Return HTTP Status Code 404 for an Error Page - SISTRIX (5)

The non-existent page https://www.sistrix.de/98899351 returns the HTTP status code 404.

Why is the correct HTTP status code for error pages important?

A web server should return either the HTTP status code 404 (Not Found) or 410 (Gone) if a URL does not exist. If there are outdated links on the web or incorrect links on your website, Google can only recognise that the target page does not (or no longer) exists by an HTTP status code 404 or 410.

That is why you need to make sure that your website’s error page always responds with the correct HTTP status code 404. Redirecting non-existent pages to the homepage through a 301 redirect is not recommended.

What exactly is a soft 404 error?

Webmasters who redirect content that no longer exists to other pages with a 301 redirect pose a problem for Google. An example:

If Google knows that the content of the page www.domain.com/recipe/how-to-make-red-gummy-bears/ is the best result for a search query for “How do I make red gummy bears?”, then Google will display this page at the top of the search results.

If the website operator now deletes this page but wants to keep the ranking for “How do I make red gummy bears?”, they can try to provide Google with a thematically similar page and point to it via a 301 redirect. In our example, this could be the category page for red gummy bears in the shop, www.domain.com/shop/red-gummy-bears/.

Google’s aim is to always provide the user with the best result for a specific search query.

However, if Google decides that the content of this page does not have the desired relevance for the search query, as was the case with the previous page, then Google can interpret this independently as a soft 404 error page.

The “soft” in this case simply describes that a page that technically does not return a 404 status code (page not found) is interpreted by Google in the same way as a page with an actual 404 status code.

What Google says

A good custom 404 page helps people find the information they're looking for, and also provides other helpful content that encourages people to explore your site further. (…) Custom 404 pages are created solely for users. Since these pages are useless from a search engine's perspective, make sure the server returns a 404 HTTP status code to prevent having the pages indexed.

Source: Search Console Help

Our Google conclusion

Pages that do not (or no longer) exist must also be clearly communicated to Google via a 404 status code.

Video Explanation by Matt Cutts / Google on this topic

Correctly Return HTTP Status Code 404 for an Error Page - SISTRIX (2024)

FAQs

How to return 404 error? ›

A web server should return either the HTTP status code 404 (Not Found) or 410 (Gone) if a URL does not exist. If there are outdated links on the web or incorrect links on your website, Google can only recognise that the target page does not (or no longer) exists by an HTTP status code 404 or 410.

How do I fix an HTTP error 404? ›

What to do if you get a 404 error
  1. Double-check the URL for typos. Only one mistyped character can result in a 404 error. ...
  2. Refresh the webpage. 404 errors might be a momentary glitch.
  3. Search the web. ...
  4. Use another device. ...
  5. Go to the Internet Archive's Wayback Machine. ...
  6. Contact the website.

How do I fix error 404 page or page Not Found? ›

5 Ways to Resolve 404 Errors
  1. Restart your browser. Try closing the current window and opening a new one. ...
  2. Clear cache. Remove your browser data and history. ...
  3. Double-check for mistyped characters. ...
  4. Use another device. ...
  5. Switch to the Incognito window.
Apr 5, 2024

What does a 404 error page look like? ›

A 404 page is also known as an “error page” or “Page Not Found” page. This page indicates that the user reached the domain they requested, but the URL path provided no information. If that sentence made your eyes glaze over, you're not alone.

How do you write error 404? ›

Creating an Error 404 Page
  1. Copy the index. php file of your current theme to a file called 404. php.
  2. Open that file and delete all sections dealing with posts or comments, see The Loop.
  3. Then, edit your 404 error message.

How do I trigger a 404 error? ›

The typical trigger for an error 404 message is when website content has been removed or moved to another URL. There are also other reasons why an error message could appear. These include: The URL or its content (such as files or images) was either deleted or moved (without adjusting any internal links accordingly)

What is HTTP code 404? ›

The HTTP 404 Not Found response status code indicates that the server cannot find the requested resource. Links that lead to a 404 page are often called broken or dead links and can be subject to link rot. A 404 status code only indicates that the resource is missing: not whether the absence is temporary or permanent.

How do I fix HTTP errors? ›

The possible fixes for this issue are:
  1. Refreshing the page.
  2. Clearing the browser cache and cookies.
  3. Loading the page with a different network.
  4. Resetting permissions for files and folders.
  5. Updating the PHP version.
  6. Regenerating the . htaccess file or correcting errors in the . ...
  7. Disabling the third-party plugins.
Nov 30, 2022

What is default 404 error page? ›

A 404 page is the HTTP standard response code that indicates that a user reached a non-existent page because of clicking on a broken link, mistyping a URL, or because the page has been deleted. In such cases, a user usually sees one of the standard messages: 404 Not Found.

What to do with 404 pages? ›

Links on 404 pages are so important because they give users a way out of the error page. Instead of closing the window or navigating away from your site, the user is able to find helpful and potentially relevant resources on another page. Some links to add to your 404 pages should include: Your home page, obviously.

How to resolve HTTP error 404? ›

1. Refresh the window or Clear the Cache. You can try refreshing the webpage because sometimes a 404 error can be due to some glitches. You can also try to clear the web browser cache to fix the 404 error.

What are two main causes of the 404 error message? ›

The most common reason you get to see a 404 error page is a website deleting content or moving it to a different URL. Other reasons for 404 error messages include: The deleting or moving of a URL without making suitable adjustments to internal links.

What is the best practice for 404 error page? ›

Avoid clutter

If you're unsure of what belongs on your 404 error page , concise, apologetic copy and a search input are more than enough to help users move forward. It's certainly not a good practice to leave users without an "exit" from a 404 page, but it's just as bad to overwhelm them with a handful of links .

What is an example of a 404 response? ›

One example of a non-existent URL that results in a 404 error is https://www.example.com/this-page-does-not-exist. If you check this URL, you will get a standard 404 error page that says, “Not Found” and “The requested URL /this-page-does-not-exist was not found on this server.”

How do I get around a 404 error? ›

How to fix 404 errors
  1. Confirm that the URL is free of typos.
  2. Clear your browser cache: Your browser may have cached an earlier version of the page.
  3. Restart your web browser, such as Google Chrome or Microsoft Edge.
  4. Visit the link in a private/incognito window. ...
  5. Try the link on a different device.
Jan 15, 2024

How do I get Google error 404? ›

You'll see this error if you visited a site or page that doesn't exist, or that you don't have permission to see. If you use Google Sites for school or work, contact your admin for help. You can also ask for help on the Google Sites Help Forum.

When to return 404 in rest API? ›

The documentation for the transition method explains that a 404 is "returned if the issue is not found or the user does not have permission to view it." Doing a GET request (`/rest/api/3/issue/12345/transitions`) successfully returns the available transitions (with their IDs).

Top Articles
Latest Posts
Article information

Author: Neely Ledner

Last Updated:

Views: 6285

Rating: 4.1 / 5 (42 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Neely Ledner

Birthday: 1998-06-09

Address: 443 Barrows Terrace, New Jodyberg, CO 57462-5329

Phone: +2433516856029

Job: Central Legal Facilitator

Hobby: Backpacking, Jogging, Magic, Driving, Macrame, Embroidery, Foraging

Introduction: My name is Neely Ledner, I am a bright, determined, beautiful, adventurous, adventurous, spotless, calm person who loves writing and wants to share my knowledge and understanding with you.