How to fix 404 Not Found errors on your site

A few 404s are normal. Sudden ones, or every page except the home page, point to a broken rewrite, a moved page or a bad link. How to find and fix them.

1–2 minutes
Hands typing on a laptop keyboard

404 Not Found means the server has nothing at that address. A handful are normal (mistyped links, old bookmarks). Many at once usually mean pages moved without redirects, or the server’s URL rewriting is broken.

If you are visiting the site

Check the address for typos, go to the home page and search, or try the site’s navigation.

If you run the site

1. Every page except the home page is 404

On WordPress and most CMSs this is a rewrite problem: pretty URLs like /about/ need the server to pass them to index.php.

  • Nginx: the location / block needs this line:
try_files $uri $uri/ /index.php?$args;
  • Apache: mod_rewrite must be on and .htaccess allowed (AllowOverride All). On WordPress, go to Settings > Permalinks and press Save to rewrite .htaccess.

2. Pages moved

Changed a slug, a category or the whole URL structure? Old links now point nowhere. Add 301 redirects from each old address to its new one. In Nginx:

location = /old-page/ { return 301 /new-page/; }

On WordPress, a redirection plugin manages these without editing server files.

3. Find them before visitors do

  • Check your access log for 404s:
sudo awk '$9 == 404 {print $7}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head -20
  • Search engines’ webmaster tools list 404s they have found and which pages link to them.

4. Missing files, not pages

404s on images, styles or scripts usually follow a migration where uploads were not copied, or a hard-coded old domain. Check the folder exists on the new server, and search the database for the old domain.

A good 404 page

Keep it helpful: say the page was not found, offer search, and link to main sections. Make sure it really returns status 404, not 200, or search engines will index it as a page.

Something out of date? Software changes. If a step no longer works, tell us and we will check it and update the page.