SITEDOCTOR

How to check a website for broken links

Broken links waste crawl budget, lose visitors and make a site look abandoned. Here are free ways to find them on one page or a whole site, and which results to double-check before you delete anything.

Short answer: for one page, run the curl loop below or paste the URL into the free W3C Link Checker. For a whole site, crawl it with wget --spider -r, lychee or linkchecker, and look at the Not found (404) list in Google Search Console. Re-check anything that says 403, 405 or 429 in a browser before you call it broken.

1. Check one page with curl

This pulls every absolute http(s) link out of the page HTML, requests each one (following redirects, 10 second timeout) and prints the ones that answer 400 or higher, or not at all (000):

URL=https://example.com/
curl -s "$URL" | grep -oE 'href="https?://[^"]+"' | cut -d'"' -f2 | sort -u |
while read -r u; do
  code=$(curl -s -o /dev/null -L -m 10 -w '%{http_code}' "$u")
  if [ "$code" -ge 400 ] || [ "$code" = 000 ]; then echo "$code $u"; fi
done

It skips relative links such as /about. If you need those too, use one of the tools in step 3, which resolve them against the page URL.

2. Crawl a whole site with wget

wget --spider -r -l 3 -nd -nv -w 0.5 -o links.log https://example.com/
sed -n '/broken link/,$p' links.log      # wget lists broken URLs at the end of the log

-l 3 limits the crawl depth and -w 0.5 waits half a second between requests, so you don't hammer your own server. Spider mode does not keep the downloaded files.

3. Dedicated free checkers

lychee https://example.com/          # fast Rust checker, also reads local files and Markdown
linkchecker https://example.com/     # Python crawler, follows the whole site by default

4. Results you should double-check

Let an AI agent check links for you

SiteDoctor is a remote MCP server (Streamable HTTP, no install) at https://manhourplan.com/doctor/mcp. Its check_broken_links tool reads the <a href> links on a page, tests up to 50 of them (default 25) with HEAD, retries with GET when a server answers 403, 405 or 501, follows redirects, and returns every link that answered 4xx/5xx or could not be reached, with its status. It costs 2 credits per call. It checks one page per call and works from the HTML, so the limits above about JavaScript links, soft 404s and anchors apply to it too.

# Claude Code
claude mcp add --transport http sitedoctor https://manhourplan.com/doctor/mcp
# then ask: "get a free SiteDoctor key and check https://example.com/ for broken links"

# raw JSON-RPC tools/call (after initialize + register_free_key, see the SiteDoctor page)
{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"check_broken_links",
 "arguments":{"url":"https://example.com/","max_links":50,"api_key":"YOUR_KEY"}}}

Result shape:

{"url": "https://example.com/",
 "links": {"checked": 50, "broken": [{"url": "https://example.com/old-page", "status": 404}], "skipped": false},
 "issues": [{"cat": "links", "sev": "high", "msg": "1 broken link(s) found in sample of 50"}]}
Run it from your agent or CI. register_free_key gives 25 free credits with no signup or card. After that, card packs: $9 for 1,000 credits, $29 for 10,000, $99 for 100,000; credits never expire. scan_website (3 credits) adds SEO, security headers, SSL and speed to the same link check.
SiteDoctor setup and free scanBuy 1,000 credits ($9, card)

The free web scan on the SiteDoctor page (5 per day) shows a score and the top issues; the full broken-link list comes from the MCP tools.

FAQ

How do I check a single page for broken links for free?

Pull the links out of the page HTML and request each one: the curl loop in this guide prints every link that answers 4xx, 5xx or not at all. The W3C Link Checker (validator.w3.org/checklink) does the same in a browser.

How do I find broken links across a whole website?

Crawl it. wget --spider -r lists broken links at the end of its log, and command-line checkers such as lychee or LinkChecker crawl and report too. Google Search Console shows internal URLs that returned 404 under Indexing, Pages, Not found (404).

Why does a working link show up as broken?

Some servers reject HEAD requests or automated clients and answer 403, 405, 429 or a custom code even though the page opens in a browser. Re-test those with GET and a normal browser before you remove them. The opposite also happens: a soft 404 page answers 200.

Can an AI agent check broken links for me?

Yes. SiteDoctor is a remote MCP server at https://manhourplan.com/doctor/mcp. Its check_broken_links tool tests up to 50 links on a page and returns each broken URL with its HTTP status for 2 credits. register_free_key gives 25 free credits; card packs start at $9 for 1,000 credits.