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.

3–5 minutes
Hands typing on a laptop keyboard

404 Not Found means the server is working but has nothing at that address. A few 404s are normal: people mistype addresses and old links break. Sudden ones are not. If every page except the home page is 404, the problem is your rewrite rules. If only some pages are, they moved or were deleted without a redirect.

If you are visiting the site

Check the address for typos, then try removing the end of it, one part at a time, to reach a page that exists. The site’s search, or a search engine with site:example.com and a few words from the title, usually finds where the page went.

Which kind of 404 is it?

PatternLikely causeGo to
Home page works, every other page is 404Rewrite rules missing or not appliedStep 1
Specific old addresses are 404Pages moved or deleted without redirectsStep 2
Pages work but images, CSS or scripts are 404Wrong paths or missing files after a moveStep 4
Every page, including the home pageWrong document root, or the site files are not where the server expectsStep 5

If you run the site

1. Every page except the home page is 404

The home page is a real file (index.php); every other address only exists because a rewrite rule sends it to that file. If the rule is missing, every other page is 404. This is the most common 404 after moving a WordPress site to a new server.

On Nginx, the site’s location / block needs a try_files line:

location / {
    try_files $uri $uri/ /index.php?$args;
}

Test and reload with sudo nginx -t && sudo systemctl reload nginx.

On Apache, the rules live in .htaccess, and Apache only reads it when the site allows it and mod_rewrite is on:

sudo a2enmod rewrite
sudo systemctl reload apache2

In the virtual host’s <Directory> block, AllowOverride All must be set, or .htaccess is ignored. On WordPress, Settings > Permalinks > Save writes a fresh .htaccess. With WP-CLI: wp rewrite flush --hard.

2. Pages moved or deleted

When you change a page’s address, add a permanent (301) redirect from the old one, so visitors and search engines follow it. On Nginx:

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

On Apache, in .htaccess:

Redirect 301 /old-page/ https://example.com/new-page/

On WordPress, the Redirection plugin manages redirects without editing files, and logs 404s so you can see which old addresses people still use.

Only redirect to a page that genuinely replaces the old one. Sending every dead page to the home page confuses visitors, and Google treats those redirects as 404s anyway (“soft 404s”). If content is gone for good with no replacement, a 404, or a 410 Gone, is the honest answer.

3. Find 404s before visitors do

Your access log lists every 404. The most common missing addresses:

sudo awk '$9 == 404 {print $7}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head -20

Many will be bots probing for files you do not have, such as /wp-login.php on a site that is not WordPress or /.env. Ignore those. Fix the ones that look like real pages.

Google Search Console’s Pages report lists 404s Google found, and where it found the link. A link checker run against your own site catches broken internal links:

wget --spider -r -nd -nv -o crawl.log https://example.com/
grep -B1 "404" crawl.log

4. Images, CSS or scripts are 404

When pages load but look unstyled or have broken images, the files they reference are missing. Your browser’s developer tools (F12, Network tab, reload) show each failed file in red with its address.

After a move, the usual reasons are:

  • Files that were not copied. Compare the file count on the old and new server.
  • Old absolute addresses still in the database, such as http://old-domain.com/wp-content/.... On WordPress, wp search-replace 'https://old-domain.com' 'https://example.com' --skip-columns=guid fixes them.
  • Case sensitivity. Logo.PNG and logo.png are the same file on Windows and macOS hosting but different files on Linux.

5. Every page is 404, including the home page

The server is looking in the wrong folder. Check the document root in the site’s configuration matches where the files are:

grep -R "root " /etc/nginx/sites-enabled/
ls /var/www/example.com/public/

On Apache the setting is DocumentRoot. Also check the request is reaching the right site: if the server name does not match, Nginx falls back to its default site, which may be empty.

A good 404 page

A 404 page should say plainly that the page is not there, keep the site’s normal header and menu, and offer a search box and links to the main sections. It must still return the 404 status code. A “not found” page that returns 200 is a soft 404, which search engines treat as low quality. Check with:

curl -s -o /dev/null -w "%{http_code}\n" https://example.com/this-does-not-exist/

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