Guide
How to fix 404 errors and set up redirects
A 404 error means the server cannot find the page at that address, and the fix is either to restore the page or to send visitors to its new home with a 301 redirect. Find broken addresses using Google Search Console and your server logs, redirect each one to the closest relevant page, and avoid sending everything to the home page.
Understanding it
What a 404 error is and when it matters
A 404 Not Found response means the server is working but nothing exists at the address requested. That can be a mistyped link, a page you deleted, an address you changed, or a link on another website that has a typing mistake in it. Some 404 errors are perfectly normal and harmless. If someone types a random address, a 404 is the correct answer.
The ones that matter are 404 errors on addresses that used to work or that other sites and search engines still link to. Visitors who land on them leave, and search engines eventually drop the page from results, losing whatever value the old address had built up.
There is also a related trap called a soft 404, where a page looks like an error to people but the server still sends a 200 success code. Search engines treat these as poor quality. A proper missing page should return a real 404 code, and a moved page should return a 301.
Status codes
Which code to use for which situation
| Situation | Right response | Why |
|---|---|---|
| Page moved for good | 301 redirect to the new address | Passes visitors and search value to the new page |
| Page moved for a short time | 302 or 307 temporary redirect | Tells search engines the old address will return |
| Page deleted, with a close replacement | 301 to the replacement | Keeps visitors on a useful page |
| Page deleted, nothing similar | 404 or 410 | Honest answer, and the page drops from results |
| Changed domain name | 301 for every old address to the same path on the new domain | Preserves every address and its history |
| HTTP to HTTPS move | 301 from http to https | Sends all visitors to the secure version |
Moving a site and want redirects done right?
Free migration is included on Small and higher plans billed yearly.
Find the problems
Finding your 404 errors
Open Google Search Console
In the Pages report, look for entries marked Not found (404). Each one is an address Google knows about that returns an error.
Check your server logs
The access log in your control panel lists every request and its status code. Filter for 404 and look for addresses that appear often.
Crawl your own site
A free crawler tool can follow every link on your site and report those that break. This catches your own typos and old menu links.
Look at your backlinks
If other sites link to old addresses, those links lead nowhere. Redirecting them recovers visitors you would otherwise lose.
Rank them by importance
Deal first with addresses that have links, traffic or are in menus. Ignore one-off typos and bots probing for files that never existed.
Doing it
How to set up a 301 redirect
There are three common ways. On WordPress, a redirect plugin gives you a screen where you enter the old address and the new one. In the control panel, a redirects tool lets you pick the domain and type of redirect without touching any code. And in the .htaccess file you can write a rule directly, which our LiteSpeed servers understand in the same way as Apache.
A simple single-page rule in .htaccess looks like Redirect 301 /old-page/ https://www.example.co.uk/new-page/. For many pages that follow a pattern, RewriteRule lines using a regular expression are more efficient than hundreds of separate lines. Always place redirect rules above the standard WordPress block, and always test after saving.
Whichever method you choose, make the redirect point straight to the final address, including the correct http or https and the correct www or non-www form. Pointing at an address that itself redirects creates a chain, which wastes time and can cause problems.
Good and bad
Redirect habits to follow and to avoid
Do this
- Redirect to the closest matching page
- Use 301 for permanent moves
- Point directly at the final address
- Keep a spreadsheet of old and new addresses
- Test every rule after adding it
Avoid this
- Redirecting every old page to the home page
- Chains of three or four redirects
- Redirect loops that never finish
- Using 302 for permanent moves
- Deleting redirects after a few weeks
Chains and loops
Redirect chains and loops
A chain happens when address A redirects to B, which redirects to C. Each hop adds delay and gives search engines more reason to give up. Fix a chain by changing the first redirect so it goes straight to C. They build up over years of redesigns, so review your list whenever you add new rules.
A loop is worse. A redirects to B and B redirects back to A, so the browser gives up and shows an error such as too many redirects. We cover that in detail in our guide to fixing ERR_TOO_MANY_REDIRECTS. The most frequent cause is two systems each trying to force their own preferred address, for example a plugin and a rule in .htaccess.
Keep your redirect list tidy and keep it for at least a year, and ideally for as long as old links exist. Removing redirects too early brings the 404 errors back.
Typical causes
Why 404 errors appear
Changed address
A page title or URL structure was edited, and old links no longer match.
Deleted content
A page, image or file was removed but is still linked.
Redesign or migration
The new site uses different addresses and nobody redirected the old ones.
Broken permalinks
On WordPress, rewrite rules got lost, and every post but the home page returns 404.
Case and slash differences
Some servers treat upper and lower case, or a trailing slash, as different addresses.
Typing mistakes elsewhere
Another site or an email campaign links to a misspelt address.
WordPress
When every page except the home page is a 404
This is a classic WordPress symptom, and it nearly always means the rewrite rules are missing. In the dashboard, go to Settings, then Permalinks, and press Save Changes without changing anything. WordPress rebuilds its rules in .htaccess. If that does not work, check that the .htaccess file exists in the site root, is readable and contains the standard WordPress block.
If it still fails, a plugin or a different rule may be interfering. Rename the plugins folder to test. After a migration, also check that the site is in the right folder and the domain points to it. Our guide to moving a website covers the points to check.
Routine
A redirect routine for any change
- Make a list of old and new addresses before the change
- Add 301 redirects the same day the change goes live
- Test a sample of old addresses in a browser
- Check there are no chains or loops
- Set a helpful custom 404 page with a search box
- Submit the new sitemap in Search Console
- Review 404 reports a week later
- Keep redirects in place for a year or more
A better 404 page
Make your 404 page useful
You will never get rid of every 404, so make the page helpful. Show the site navigation, a search box and links to your most popular pages, and use a friendly tone that matches your brand. Make sure the page returns a real 404 code rather than a 200, which a good WordPress theme handles for you.
A useful 404 page turns a dead end into a second chance. A visitor who lands on a clear page with a search box often finds what they wanted, where a bare error would have sent them straight back to the search results.
FAQ
Common questions
Does a 404 error hurt SEO?
A few 404s are normal and do no harm. Many 404s on pages that had links or traffic can lose you value, so redirect those.
Should I redirect all 404s to the home page?
No. Redirect each to the most relevant page. Mass redirects to the home page are often treated by search engines as soft 404 errors.
What is the difference between 301 and 302?
A 301 is permanent and a 302 is temporary. Use 301 when the move is for good.
How long should I keep redirects?
At least a year, and longer if old addresses still get links or visits.
Why do I see 404s for files I never had?
Bots probe for common files and plugin paths. These are harmless, and you can ignore them unless they are numerous.
Keep reading
Related pages
Move your site without losing visitors
Free migration on Small and higher plans billed yearly.