Sub topic 9
Crawling your site to find broken links
This chapter assumes you can read HTTP status codes (200, 301, 404, 410, 500) and know the difference between a redirect chain and a loop. It also assumes you are comfortable running commands in a terminal.
What a crawler does
A site crawler starts at one or more URLs, downloads each page, extracts the links, and requests those links in turn. For every URL it records the status code, the redirect target, and the pages that linked to it. The last column is the one that matters most for fixing: a 404 is only actionable once you know which page contains the bad link.
Choosing a crawler
- Desktop crawlers such as Screaming Frog SEO Spider show status codes, redirect chains, and "inlinks" (the pages linking to a URL) in tables you can export.
- Command-line tools such as
wgetare free and scriptable, but report less. - Hosted monitors crawl on a schedule and send alerts. They suit ongoing checks, covered in a later chapter.
A quick crawl with wget
The --spider option makes wget check URLs without saving them. -r follows links recursively, and -l 5 limits depth to five levels.
wget --spider -r -l 5 -o wget.log https://example.com/
grep -B4 'broken link' wget.logEach match shows the URL that failed. This tool will not give you a full list of source pages, so use a dedicated crawler when you need to find where each bad link lives.
Settings that change what you find
- Scope. Crawl internal URLs to find links you can fix. Enable external link checking too, because outbound links rot over time.
- Redirect handling. Make the crawler report each redirect rather than silently follow it. Otherwise chains stay hidden behind a final 200.
- Rendering. Links added by JavaScript only appear if the crawler renders pages. Turn on JavaScript rendering for single-page apps, and expect slower crawls.
- Speed. Limit concurrent requests so the crawl does not overload your server or trigger rate limits, which would show up as false 429 or 503 errors.
- Robots rules. Decide whether to obey
robots.txt. Obeying it matches what search engines see. Ignoring it, on your own site, reveals blocked sections.
Reading the results
Filter the report by status class first:
| Finding | What to look for | Likely action |
|---|---|---|
| 404 or 410 on internal links | Source pages in the inlinks list | Edit the link on each source page |
| 3xx internal links | Redirect target column | Link to the final URL directly |
| Chains of two or more hops | Hop count | Collapse to one hop |
| Loop or "too many redirects" | Repeating URLs | Fix the server rule |
| 5xx | Retry the URL once | Investigate the server if it persists |
Re-test any 5xx or timeout before acting. A single failure may be temporary load.
Limits of crawling
A crawler only finds pages reachable by links from its seed. Orphan pages, which have no inbound links, never appear. Pages behind logins also stay hidden unless you configure authentication. Seeding the crawl with your XML sitemap helps cover orphans. Server logs and Search Console, covered next, catch what links alone miss.
Exercise
A crawl shows 40 internal URLs returning 404. What extra information do you need from the crawler before you can fix them, and why?
Show answer
The list of source pages that link to each 404 URL (the inlinks). Without it you know which URLs are broken but not where the bad links are, so you cannot edit them. Then fix the links on those pages, or add a redirect if the content moved.