404 Not Found: Causes, Fixes and Good Error Pages
Find out why a page returns 404, fix it as a visitor or site owner and build an error page that helps people move on.
Key takeaways
- A 404 comes from a server, so it is a different problem from a failed connection or an unknown domain name.
- Typos, moved or deleted pages and wrong rewrite rules cause most of them.
- A moved page deserves a permanent redirect to its closest replacement, and a removed one can honestly return 404 or 410.
- An error page must send the 404 status itself, or search engines and monitors will be misled.
- Many 404s in logs come from automated scanners and need no fix.
A 404 Not Found response means the server was reached and answered, but it has nothing to show at the address you asked for. Your connection works. The problem is the address, the content behind it or the server's rules for matching one to the other.
If you are a visitor, check the address and look for the page from the site's home or search box. If you run the site, find out where the bad request came from, then restore the page, redirect it or let the 404 stand and make the error page useful.
What the code says, and what it does not
RFC 9110 defines 404 as the server not finding a current representation for the target, or not being willing to disclose that one exists. It does not say whether the page ever existed, or whether it will come back.
Two neighbors are worth knowing. 410 Gone says the resource was removed and this is likely permanent. 403 Forbidden says the server refuses access. Some sites deliberately answer 404 where 403 would be accurate, so that outsiders cannot learn which private pages exist.
Do not confuse a 404 with messages like "server not found" or "this site can't be reached". Those mean no web server answered at all, usually because of DNS or the network. Connection errors cover that family.
If you are the visitor
Try these in order:
- Reload the page once, in case of a momentary glitch.
- Check the address for typos, missing characters or punctuation stuck to the end when it was copied from a message.
- Mind capital letters. On many servers the path is case-sensitive.
- Shorten the path. Remove the last segment and try the parent section.
- Use the site's search, or a search engine restricted to that site with
site:example.com router guide. - Try a private window, which rules out an old cached redirect or stored cookie.
- Look for an archived copy in a public web archive.
- Tell the site owner, including the page that held the broken link.
Changing DNS servers or resetting your router will not help with an ordinary 404, since the website itself produced it.
Why sites produce them
| Cause | Typical sign |
|---|---|
| Page moved or renamed | Old links and bookmarks fail after a redesign |
| Page deleted | A product or article was removed |
| Typo in a link | Only one link to the page fails |
| Wrong relative link | Works from one folder, fails from another |
| Case mismatch | Worked on a laptop, fails on the live server |
| Missing rewrite rules | Home page works, every inner page fails |
| Incomplete deployment | New files absent or old filenames referenced |
| Wrong site answering | DNS or virtual host points elsewhere |
The case-mismatch row catches many people. Windows and macOS file systems usually ignore case by default, while typical Linux servers do not. Photo.JPG referenced as photo.jpg works at home and breaks in production.
URL anatomy explains how relative links resolve, which accounts for another large share.
Diagnosing as the site owner
Confirm the status first, from outside your own browser cache:
curl -sI https://www.example.com/old-page Use curl.exe in Windows PowerShell 5.1. Then work through the layers.
Content management systems often use "pretty" addresses that depend on the web server passing unknown paths to one program. If that rule disappears after a migration, inner pages all return 404. Resaving the permalink settings in the CMS, or restoring the server rule, usually fixes it.
In nginx, a common form of the rule is:
location / {
try_files $uri $uri/ /index.php?$args;
} Apache uses rewrite directives in the virtual host or .htaccess, which only work if the rewrite module is enabled and overrides are allowed.
Single-page applications have a related problem. The app handles /settings in the browser, but when someone loads that address directly, the server looks for a file and finds none. Configure the server to return the application's entry page for its routes, while still returning a real 404 for addresses the app does not recognize.
Redirect, restore or leave it
When content moves, send a 301 or 308 to the new location. Redirect each old address to its closest equivalent. Sending everything to the home page confuses visitors, and search engines may treat it as a soft 404. See choosing a redirect code and redirecting pages without losing visitors.
When content is gone with no replacement, a 404 is correct. A 410 states the intent more firmly. Neither one harms the rest of the site. Broken links that people still follow are the ones worth your time.
Soft 404s
A soft 404 is a "not found" page delivered with a success status, or a redirect that leads somewhere unrelated. Visitors read the apology, but software sees a valid page. Search engines may index many copies of it, and uptime tools report all is well.
Check your own site by requesting a made-up address:
curl -s -o /dev/null -w "%{http_code}\n" https://www.example.com/this-page-should-not-exist The answer should be 404. In Windows PowerShell, use curl.exe and NUL in place of /dev/null.
A frequent cause is an error page configured as a full URL. In Apache, ErrorDocument 404 /404.html serves the page and keeps the status, while giving a complete https:// address turns it into a redirect.
Building a good error page
Write it for someone who is mildly annoyed. State what happened without blaming them. Offer two or three useful routes, not a wall of links. Humor is fine if it does not push the useful parts out of view.
Technically, keep it light and self-contained. Use root-relative paths such as /styles.css for its assets, because the page can appear at any depth and ordinary relative paths would break. Do not make it depend on the database that might be the reason for the failure. Designing error messages that help has more on wording.
Finding and prioritizing broken links
Your access logs record each 404 with its path and often a referrer. On Linux, with a common log format, this lists the most frequent ones:
awk '$9 == 404 {print $7}' access.log | sort | uniq -c | sort -rn | head -20 Field positions depend on your log format, so check a few lines first. Search engine webmaster tools also report addresses their crawlers could not find.
Sort the results into three piles:
- Your own broken links. Fix these at the source.
- Other people's links and old bookmarks to content that moved. Redirect them.
- Noise. Requests for admin pages of software you do not run, backup files or configuration files are automated probing. A 404 is the right answer. Just make sure no real sensitive files are reachable.
Missing files that are not pages
Images, scripts, stylesheets and fonts can 404 too, and the page itself may look broken or half-styled with no error message. Open the Network tab, reload and filter for failed requests. Check favicon.ico, which browsers request on their own, and any files named in your HTML after a build step renames them.
If a script request receives your HTML error page, the console may complain about an unexpected < or a wrong media type. The real issue is the missing file.
A worked investigation
Say you reorganize a small business site, moving service pages from /services.php?id=3 style addresses to readable ones such as /services/roof-repair/. A week later the logs show hundreds of 404s.
Sorting by path shows three groups. The first is the old query-string addresses, still linked from directories and bookmarks. A redirect rule that matches on the path alone will not help, because the identifier lives in the query string. You need a rule that reads id and maps each value to its new page.
The second group is /services/roof-repair/images/before.jpg. A template uses a relative image path, images/before.jpg, which resolved correctly at the old depth and no longer does. Changing it to a root-relative path fixes every page at once.
The third group is requests for login pages of software the site never ran. Nothing to do there.
The example shows why reading actual paths beats guessing: three problems that all look like "404" needed three different answers.
Caching and stale 404s
A 404 can be cached. The standard allows caches to reuse it under heuristic rules, and content delivery networks often keep error responses for a short period. So a file you have just uploaded may keep returning 404 to some visitors.
If that happens, request the address with developer tools open and look for headers such as Age or a cache status field from your network. Then purge that one address in the CDN. To avoid the problem, upload new files before publishing pages that refer to them, and do not test an address in public before its content exists. Making updates appear covers purging.
Preventing the next batch
Keep addresses stable. Before a redesign, export the list of existing URLs and map every one to its new home or a deliberate removal. After launch, crawl the old list and confirm each ends at a 200 or an intended 404 or 410. Then watch the logs for a few weeks, since the links you forgot will announce themselves.