Ahosting Logo
Knowledge Base

How to Find and Fix Broken Links on Your Site

The referrer in the 404 log is the whole diagnosisWhere did the 404 come from?YesYour own sitea broken internal link: fix it in the content, atthe sourceNoSomewhere else, or nowherean outside link or a probe: redirect the valuableones, ignore the noiseMost 404s in a busy log are automated probes for files that never existed. Filtering those first makes the real listshort.

Broken links accumulate on every site: pages get renamed, external sites disappear, images are deleted from the media library. Each one is a visitor reaching a dead end, and on a site of any age there are usually more than anyone expects.

Two kinds, with different fixes

Internal: a link from your site to a page on your site that no longer exists. Entirely your problem and entirely fixable.

External: a link to somebody else's site that has moved or gone. You cannot fix their site; you can update or remove the link.

A third case is worth separating: a link from another site to a page of yours that no longer exists. That is not a broken link on your site: it is a redirect you have not written, and it is usually the most valuable of the three because someone is sending you traffic.

Find them in the log first

Before running a crawler, read what is actually happening.

The access log records every 404 with the address requested and the referring page. That referrer is the whole diagnosis: a 404 referred from your own site is a broken link you can fix, and one referred from elsewhere is a redirect worth writing. How to View and Analyze Website Statistics in cPanel goes into reading it.

This also ranks the problem by how much it matters. A 404 nobody has requested is theoretical; one requested a hundred times a week is costing you.

Ignore the background noise

A large share of your 404s are automated systems probing for paths that never existed, wp-login.php on a site with no WordPress, administrator panels for software you do not run, files with names nobody would type.

Those are not broken links and they never will be. Do not write redirects for them, and do not let them make the report look alarming.

The useful filter is the referrer: real broken links have one, and probes usually do not.

Then crawl the site

A crawler follows every link and reports what it got, which finds the links nobody has clicked yet.

Do it from outside rather than with a plugin where you can. A plugin crawling your own site consumes your own resources, and on shared hosting a scan of a large site can be enough to hit a limit, which turns a tidying exercise into an outage.

Check the search console too. Its crawl errors are what a search engine encountered, which is the list that affects how your site is indexed.

Fix internal links at the source

A redirect makes a broken internal link work. It does not stop it being wrong.

Editing the link in the content is the fix; the redirect is for addresses you no longer control. A site held together by redirects for its own internal links has a hop on every click and a map nobody can follow. How to Redirect a Domain or Page sets out when a redirect is right.

Where the page genuinely moved, redirect and update the internal links. Both, not either.

Redirect to the equivalent page

For inbound links to pages that are gone, send each to the closest match.

Sending everything to the homepage is better than a 404 and considerably worse than a real match: the visitor has to find what they wanted and most will not, and search engines treat it as a page that vanished rather than one that moved.

Where nothing equivalent exists and the page is genuinely retired, a 410 is more precise than a 404. It says gone deliberately, and the address is dropped more decisively. There is more on the difference in Understanding HTTP Status Codes.

Broken images are broken links too

And they are easier to miss, because the page loads.

The usual causes are an image deleted from the media library while still referenced in a post, and a site moved to a new address where the content still points at the old one, which a database replacement should have fixed. For that, see How to Change Your WordPress Site URL.

A crawler reports missing images alongside missing pages. So does the browser's own console on any page you open.

External links: decide a policy

Links to other sites break at a steady rate and there is no fixing the far end.

For each one: update it if the page moved, replace it if something better exists, or remove it. Removing is a legitimate answer; a link to a page that no longer exists helps nobody.

Do not use an archive link as a default. It is right when the original content matters historically and wrong when the reader wanted current information.

Make it a habit instead of a project

Check the 404 log monthly; it takes five minutes and catches things while they are small.

Crawl the site properly once or twice a year, and always after a migration, a restructure or a domain change: those are when broken links arrive in bulk in place of one at a time. How to Move a Website to a New Domain sets out the largest version of that.

A custom 404 page makes the rest cheaper

You will never find every broken link. A 404 page with a search box, a link to the homepage and your main sections turns the ones you missed into a recoverable moment.

It is twenty minutes of work that pays off on every dead end you have not found yet. How to Create a Custom Error Page explains writing one.