Skip to main content

How do I force a 404 status code

If your 404 page is returning a Status Code 200, you should check your web server and see why, we've detailed some configuration options below for various servers and technologies which may help.

Apache

Check out your .htaccess file (or httpd.conf / apache2.conf for global settings)

Look for ErrorDocument and if it isn't there, try adding something like this:

    ErrorDocument 404 /custom-404.html

Apache will now look for a page called custom-404.html and display that with the status code 404.

NGINX

For NGINX we want to take a look at the server block in /sites-available

    server {
listen 80;
server_name example.com;

error_page 404 /custom-404.html;
location = /custom-404.html {
internal;
root /path/to/your/pages;
}
}

The lines we want to focus on are error_page below which tell NGINX that the custom-404.html page is the 404 page and to return that with a 404 status code.

Microsoft IIS

IIS is a little different as you get to use the GUI!

  1. Open IIS Manager and navigate to your website.
  2. In the Features view, double-click "Error Pages".
  3. In the Actions pane, click "Add" to add a new error page or click "Edit" to modify an existing error page.
  4. Enter 404 as the status code, and set the path to your custom error page.
  5. Make sure to choose the option to return the custom error page with a 404 status code.

After you've changed it

Remember to restart your web server and head over to Little Warden to check that it's responding correctly!