Creating custom 404 and error pages
Replace the plain server error pages with your own 404, 403 and 500 pages using .htaccess, and make sure a 404 still returns the right status code.
On this page
1. Create the pages
In public_html, create simple HTML pages such as 404.html and 500.html. A good 404 page:
- says clearly the page wasn’t found
- links to the home page and key sections
- offers search if your site has it
- uses the same design as the site
Use absolute paths for CSS and images (/css/style.css), because the page is shown at whatever URL was requested.
2. Point the server at them
In public_html/.htaccess:
ErrorDocument 404 /404.html
ErrorDocument 403 /403.html
ErrorDocument 500 /500.htmlUse a local path, not a full URL. A full URL makes the server redirect to the page, returning a 302 status instead of 404, which tells search engines the missing page exists.
3. Test
Visit a URL that doesn’t exist, such as /this-does-not-exist. Your page should appear, and in browser developer tools (Network tab) the status should be 404.
WordPress and frameworks
These handle their own 404s through the theme (404.php) or application routing. ErrorDocument still covers files outside the application.
Keep the 500 page simple
If PHP is what’s failing, a 500 page that uses PHP fails too. Make it plain HTML.
Prefer to follow along?
- Redirect old URLs after a redesign
Intermediate · 30 min
Traxio accounts include SSH, Git, cron and PHP 7.4 to 8.4. Try the PHP hosting is £0.99 a month.
Common questions
Can I use my own 404 page?
Yes — create the page, then point the server at it with an ErrorDocument line in .htaccess. A custom 404 that links back to your main sections keeps visitors who hit a dead link rather than losing them.
Spotted something out of date or unclear? Tell us and we’ll fix it.