Sub topic 3
Why links break
This chapter covers the causes of broken links. It assumes you can read an HTTP status line and that you know the difference between a 200, a 301, and a 404. If you can't yet, review the status code chapter first. Fixes and redirect syntax come in later chapters. The goal here is to look at a 404 and name its cause, because the cause decides where the fix goes.
A broken link has two ends
Every link joins a source page to a target URL. The source contains the <a href>. The target is what the server returns when that URL is requested. A link is broken when the target answers with an error, usually 404 or 410. Sometimes it answers with a 5xx error or never answers at all.
Two questions classify nearly every break:
- Did the target ever exist at that URL?
- Do you control the source, the target, both, or neither?
Your answers decide whether you edit a link, add a redirect, or leave the URL alone. The diagram shows the usual order of triage.
Typos and malformed links
The target never existed. These are the easiest breaks to find, and they come from a short list of mistakes:
- A mistyped slug, such as
/prcinginstead of/pricing. - A missing scheme or a doubled one, such as
href="www.example.com/page". Browsers read this as a relative path and append it to the current URL. - A relative path that resolves differently than the author expected. On
/blog/post-1/, the linkhref="images/a.png"points to/blog/post-1/images/a.png. On/blog/post-1with no trailing slash, it points to/blog/images/a.png. - Trailing punctuation copied into the URL, such as a closing parenthesis, a period, or a comma from a sentence. Chat apps and Markdown renderers do this often.
- Unencoded spaces or special characters, such as
%20written as a literal space.
Typos in your own pages are also visible in your access logs. If a person made the typo, many different referrers rarely hit it. If a template made it, the same bad URL appears on thousands of pages.
Moved or renamed content
The URL used to work, and the content still exists at a new address. This is the most common cause on sites that have been running for more than a year. Typical triggers:
- Changing a slug when you edit a title in a CMS.
- Reorganizing categories, so
/blog/seo-tipsbecomes/guides/seo/tips. - Moving from HTTP to HTTPS, changing the domain, or dropping
www. - Changing the file extension, as in
/page.htmlto/page. - Redesigning the site and regenerating all URLs.
The old URL keeps living in other places: your own internal links, bookmarks, sitemaps, and links from other sites. If the server does not redirect, all of them break at once. These breaks are the best candidates for a redirect, because the content has a real successor.
Deleted content
The content is gone. A server can say so in two ways:
| Status | Meaning | When it fits |
|---|---|---|
| 404 Not Found | The server has no resource here and makes no claim about why or for how long. | Default for unknown URLs, typos, and anything you haven't decided about. |
| 410 Gone | The resource existed and was removed on purpose. It is not coming back. | Discontinued products, expired campaigns, content you deliberately retired. |
Google has said it treats the two similarly for indexing, so 410 is not a ranking tool. It does record your intent for humans reading logs and for tools that distinguish the two. Do not use 410 when you are unsure. Once you tell clients that something is permanently gone, it is awkward to reverse.
Link rot on external sites
Link rot is the slow decay of links to pages you don't control. Your link was valid when you wrote it. Later the other site restructured, the company shut down, a domain expired, or a page moved behind a login. You can't fix the target. You can only update or remove your link.
Studies of old web content consistently find that a large share of links stop working within a few years. Your oldest articles are the most exposed. A blog post from 2018 with ten outbound links probably has at least one dead one now.
Causes that come from the server or platform
Some links look broken but trace back to configuration. Check these before you blame an author.
- Case sensitivity. Linux file systems treat
/About.htmland/about.htmlas different files. A site built on a case-insensitive system, such as Windows or macOS, can work locally and then 404 in production. - Trailing slashes.
/guidesand/guides/can behave differently depending on the server and framework. - Query strings and fragments. A link with
?ref=newslettermight hit a router that doesn't expect parameters. - Environment leaks. Absolute links to
staging.example.comorlocalhost:3000that were published to production. - Missing assets. Images, PDFs, CSS, and JavaScript files deleted or renamed while pages still reference them.
- Stale generated URLs. XML sitemaps, canonical tags, and hreflang annotations that still list removed URLs.
- Intermittent 5xx errors. A page that fails under load is unreachable, but it is not a missing page. Treat it as an availability problem and don't delete or redirect it.
Telling the causes apart in practice
Start by ranking the broken URLs in your access log. This command lists the 20 most requested 404 paths, assuming the common or combined log format:
awk '$9 == 404 {print $7}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head -20Then look for patterns in the output. Trailing punctuation suggests copy-paste damage:
awk '$9 == 404 {print $7}' /var/log/nginx/access.log | grep -E '[).,;]$|%29$' | sort | uniq -c | sort -rn | headTest case sensitivity directly. If the lowercase URL returns 200 and the mixed-case one returns 404, you have found a case mismatch:
for path in /About-Us /about-us; do
printf '%s -> ' "$path"
curl -s -o /dev/null -w '%{http_code}\n' "https://example.com$path"
doneA few signals narrow down the cause quickly:
- Many hits from many referrers to a URL that looks well formed point to moved content. People have the old URL saved.
- Hits with an internal referrer point to a broken link on your own pages. Fix the source link.
- Hits with no referrer, from bots probing paths such as
/wp-login.phpor/.env, are noise. They aren't broken links and don't need fixing. - A burst of 404s that starts on a specific date matches a deploy, a migration, or a slug change made that day.
What to record for each break
For every broken URL you investigate, note four things: the cause category from this chapter, the referrer that led to it, whether you own the source, and whether a successor page exists. These four facts feed the prioritizing and fixing chapters later, and they make the choice between "edit the link", "add a redirect", and "do nothing" straightforward.
Exercise
Your 404 report shows /blog/2021/pricing-guide receiving 300 hits a month, mostly from external referrers. Last quarter you changed the blog URL structure and the guide now lives at /guides/pricing. Which cause is this, and why can't editing your own internal links fully fix it?
Show answer
This is moved or renamed content without a redirect. The URL once existed and the content survives at a new address. The traffic comes from external referrers, which are links on sites you don't control, plus bookmarks. You can only update links on your own pages, so the old URL itself must answer with a redirect to /guides/pricing.
Exercise
A page returns 404 only in production, and its link works on a developer's Mac. The file on the server is named About-Us.html and the link says /about-us.html. What is the likely cause?
Show answer
Case sensitivity. The developer's macOS file system matched the names regardless of case. The Linux production server treats About-Us.html and about-us.html as different files. Fix it by making the link and the file name consistent, preferably all lowercase.