A well-designed 404 page improves user experience for lost visitors and, correctly configured, preserves proper SEO signals — this guide covers implementing 404 handling correctly for a static site.
Why Correct 404 Handling Matters Beyond Just Showing a Page
Beyond user experience, a 404 page must actually return a genuine HTTP 404 status code — a common static site mistake is serving 404-styled content while returning a 200 status, confusing both users and search engines about whether the page genuinely exists.
Configuring a Custom 404 Page in Nginx
error_page 404 /404.html;
location = /404.html {
root /var/www/mysite;
internal;
}
Serves your custom-designed 404 content while still correctly returning a 404 status code — the essential combination many static site setups get wrong.
Verifying Your 404 Actually Returns Status 404
curl -I https://yourdomain.com/this-page-does-not-exist
Confirm the response includes HTTP/1.1 404 Not Found — if you see 200 instead, your configuration is serving 404 content with an incorrect success status, a genuine SEO and correctness issue.
Designing a Genuinely Useful 404 Page
- Clear messaging that the page wasn't found (avoid overly clever/confusing copy that obscures the actual situation)
- Navigation back to key site sections (home, search)
- If you have site search (see How to Add a Search Feature to a Static Site), include it directly on the 404 page
Handling 404s for Single Page Applications Differently
See How to Configure Nginx for Single Page Applications (SPA Routing) — SPAs have a different consideration, since client-side routing means the server can't always know in advance whether a path is genuinely invalid or a valid client-side route; SPA 404 handling typically happens client-side after the app loads and determines the route is invalid.
Redirecting Known Old URLs Instead of 404ing Them
See How to Set Up Redirects and Rewrites for a Static Site — for URLs you know moved (not genuinely gone), a 301 redirect to the correct new location is preferable to a 404, preserving both user experience and SEO value rather than sending visitors and search engines to a dead end.
Monitoring 404 Occurrences
Review your access logs periodically for frequent 404 patterns — recurring 404s on a specific URL suggest either a broken internal link you should fix, or an opportunity for a redirect if that URL represents genuinely moved content that people are still trying to reach.
Ensuring the 404 Page Itself Loads Fast
Your 404 page is still a real page visitors see — apply the same performance considerations (see Understanding Core Web Vitals for Static Sites) as your regular pages; a slow-loading 404 page compounds a visitor's already-frustrating experience of not finding what they wanted.
Common Errors
404 page displays correctly but search engines report indexing issues — almost always the status code mismatch issue (200 instead of 404); verify with the curl check above, since this is the most common root cause of this specific symptom.
Continue Reading
- How to Set Up Redirects and Rewrites for a Static Site
- How to Configure Nginx for Single Page Applications (SPA Routing)
- How to Add a Search Feature to a Static Site (Client-Side Search)
Browse more articles in Static Site Hosting & Frontend Deployment.