Sub topic 3
Why links break
This chapter covers the causes of broken links so you can recognize them when you find them. It assumes you know how a browser requests a URL, what an HTML anchor tag is, and the basic status codes (200, 301, 404, 410, 500). Later chapters cover detection and fixes.
What "broken" means
A link is broken when following it does not reach the content the author intended. Usually the server answers with a 4xx or 5xx status. Sometimes the request never gets an answer at all, for example when DNS fails or the connection times out. A link can also return 200 and still be broken if it lands on the wrong page. Soft 404s are covered in their own chapter.
The main causes
| Cause | What happens | Typical status |
|---|---|---|
| Content moved without a redirect | The old URL no longer maps to anything | 404 |
| Content deleted on purpose | The page was removed and nothing replaced it | 404 or 410 |
| Typo in the link | The author mistyped a path, or the link has a trailing character, wrong case, or stray whitespace | 404 |
| Link rot on external sites | The other site restructured, was sold, or shut down | 404, 410, or no response |
| Domain or DNS problems | The domain expired or the DNS record was removed | No response |
| Server errors | The application fails on that URL | 500, 502, 503 |
| Protocol or host changes | A link to `http://` or to an old hostname is no longer served | Error or redirect |
Moved and deleted content
The most common internal cause is a URL change with no redirect. A slug is edited in the CMS, a category is renamed, or a section is reorganized. Every inbound link to the old path, from your own pages, from other sites, and from search results, now returns 404.
Deletion is different. If you remove a page on purpose and no replacement exists, a 404 is acceptable. A 410 (Gone) states that the removal is permanent. Both are correct behavior. The mistake is deleting a page that still has links pointing to it and never checking.
Typos and malformed URLs
Typos are easy to miss because the page looks fine in the editor. Common forms:
- A missing or extra path segment, such as
/blog/postinstead of/blog/posts/post. - Case differences. Paths are case-sensitive on most Linux servers, so
/Aboutand/aboutcan be different URLs. - Relative links that resolve differently depending on the page they sit on.
href="images/a.png"andhref="/images/a.png"are not the same. - Copy-pasted URLs with trailing punctuation, such as a period or a closing parenthesis.
<!-- Resolves relative to the current page's directory -->
<a href="guides/setup">Setup</a>
<!-- Resolves from the site root, regardless of the current page -->
<a href="/guides/setup">Setup</a>Link rot
Link rot is the gradual decay of links to pages you do not control. You cannot fix the target, so you decide what to do with the link: update it, point to an archived copy, or remove it. Because external sites change without notice, a link that worked at publication will eventually fail. Old content is the most exposed.
Where breakage comes from over time
Exercise
Your team renames the URL /products/widgets to /shop/widgets and does not add a redirect. Name two kinds of links that now break, and say which status code you would expect.
Show answer
Internal links from your own pages, and inbound links from other sites or search results, both break. Bookmarks break too. The old URL would normally return 404, because the server has no content mapped to that path.
Exercise
A link on your site points to /About, but the page lives at /about. Why might this work on your laptop and fail in production?
Show answer
Some development environments, such as case-insensitive file systems on macOS or Windows, treat both paths as the same file. Most Linux production servers treat paths as case-sensitive, so /About returns 404.