Sub topic 3
What Makes a Link Broken: Status Codes, Redirects and Soft 404s
This chapter assumes you know what a backlink is, can read an HTML anchor tag, and recognise the status codes 200, 301 and 404. It builds on those to decide which links are worth pursuing as broken link opportunities.
Why the definition matters
A link is broken if a visitor who follows it cannot reach the content it promised. Browsers can hide this. A page that looks fine may be a redirect to an unrelated page. A page that looks dead may only be blocking your tool. If you misjudge these cases, you will send outreach about links that are not broken.
Status codes and what they mean
| Status | Meaning | Broken for outreach? |
|---|---|---|
| 200 | Page loaded | No, unless it is a soft 404 |
| 301, 308 | Moved permanently | Usually no, follow the chain |
| 302, 307 | Moved temporarily | Usually no |
| 403, 405, 501 | Server refused your request method or tool | Unknown, retry with GET |
| 404 | Not found | Yes |
| 410 | Gone on purpose | Yes, a strong signal |
| 500 and above | Server error | Maybe, recheck later |
A server error can be temporary. Check it again on another day before you treat it as dead. A connection failure, such as an expired domain or a DNS error, has no status code at all. It is still a broken link.
Redirects
Your tool should follow redirects to the final URL, then judge that response. A 301 that ends at a working page on the same topic is not broken. A chain that ends in a 404 is broken, even though the first response was a 301.
Soft 404s
A soft 404 is a page that says "not found" to the reader but returns status 200. Common forms are an error message on a normal template, an empty search result, or a redirect of every dead URL to the homepage. A status check alone misses all of these.
Checking for soft 404s in code
This function reports the final status and flags a redirect to the homepage or error wording in the page text.
import requests
from urllib.parse import urlparse
PHRASES = ("page not found", "no longer available", "doesn't exist")
def classify(url, timeout=10):
try:
resp = requests.get(url, timeout=timeout, allow_redirects=True)
except requests.RequestException:
return "broken: no connection"
if resp.status_code in (404, 410):
return "broken: " + str(resp.status_code)
if resp.status_code >= 500:
return "recheck: server error"
if resp.status_code >= 400:
return "unknown: " + str(resp.status_code)
original_path = urlparse(url).path
final_path = urlparse(resp.url).path
if resp.history and final_path in ("", "/") and original_path not in ("", "/"):
return "suspect: redirected to homepage"
text = resp.text.lower()
if any(p in text for p in PHRASES):
return "suspect: error wording on page"
return "ok"
print(classify("https://example.com/old-guide"))Exercise
A tool requests https://site.test/guide and receives a 301 to https://site.test/, which returns 200. Is the link broken, and how would you confirm it?
Show answer
It is probably a soft 404 in the form of a homepage redirect. The final status is 200, but a specific guide was replaced by the homepage. Open the original URL in a browser, and check a web archive copy to see whether the guide's content still exists anywhere on the site.