How to Create a helpful 404 page

Things get lost, deleted, links point to the wrong location. These things happen. When they do it is best for the user experience to create a useful 404 Not Found page.

Unfortunately, developers will sometimes create a redirect or return a page without the 404 status code. This is called a soft 404 page, and it is bad. Don't do it!

Instead, make your 404 page helpful, but keep that 404 status code.

Creating a custom 404 page is very simple. First, create a page that will function as the 404 page. Then add the following code to your .htaccess file.

ErrorDocument 404 /error/custom404.php

You should change /error/custom404.php to the location of your 404 page.

You can set custom error pages for more than just 404 errors.

ErrorDocument 401 /error/custom401.php
ErrorDocument 403 /error/custom403.php
ErrorDocument 404 /error/custom404.php
ErrorDocument 500 /error/custom500.php
ErrorDocument 502 /error/custom502.php
ErrorDocument 503 /error/custom503.php
ErrorDocument 504 /error/custom504.php

You should note that if you have a 5XX Server Error your nice error page may not be able to be served. It depends on the exact nature of the error itself. However, you should create them anyway.

Daniel Morell

Daniel Morell

I am a self-taught web developer with a passion for SEO, creating stunning websites, and organic marketing. I am a perfectionist. That means I get obsessed with the nitty-gritty details.

I live in Wisconsin's Fox Valley with my beautiful wife Emily.

Daniel Morell

I am a self-taught web developer, SEO, and builder of things (mostly digital).

I started with just HTML and CSS, and now I mostly work with Python, PHP, JS, and Golang. The web has a lot of problems both technically and socially. I'm here fighting to make it a better place.

© 2018 Daniel Morell.
+ Daniel + = this website.