squirrelscan
GitHub

Broken links: internal, external and how to find them

A broken link points at a target that answers with an error, does not resolve or is malformed. Internal, external and fragment links, and how to find them.

A broken link is a link whose target answers with an error status, fails to resolve at all, or is written so badly that it cannot be followed.

There are several kinds. An internal link to a page that answers 404 or 500 is a dead end on your own site. An external link can break when another site moves or shuts down, and the request may fail outright on DNS or TLS. A fragment link such as /pricing#team breaks when the target page has no element with id="team" and no <a name="team">. A malformed href never had a target in the first place. Google treats a 4xx response other than 429 as content that does not exist.

Category: Links

Why it matters

A broken link costs a visitor a click and a crawler a request, on every page that carries it. Internal links break quietly when a page is renamed and the old links stay in body copy and menus. External links decay with time. Some links only look broken, though. A site behind bot protection can refuse an automated check and still load fine in a browser, so a link checker has to keep “broken” and “could not verify” apart.

How squirrelscan checks it

links/broken-links compares every internal link with the status the crawl recorded and fails targets that answered 400 or above, listing the pages that link to each. Rate-limited and refused targets are reported as unverifiable, and targets the audit never fetched are not counted as broken. links/broken-external-links reads the external link check, which runs only when external link checking is on, and groups failures by status. Links that bot protection refused, or that timed out, are listed as unverified. links/dead-links is an info-level summary of the same check. links/broken-anchors checks each fragment against the ids on the crawled target page, case-sensitively, as browsers do. links/invalid-links reports hrefs the parser could not resolve. images/broken-images flags an empty, # or data:error image source. It sends no request, so a well-formed image URL that answers 404 passes.

RuleWhat it flagsSeverity
Broken internal links: 404s inside your own siteAn internal link to a page that returns 404 or 500 is a dead end you control. squirrel cross-references every internal link against the crawl.error
Broken external links: link rot on pages you cannot fixExternal links die without warning when the other site changes. squirrel checks each one and separates dead links from unverifiable ones.warning
Cloud dead-link checking: the shared external link cacheChecking every external link from your machine is slow and rude to the sites you link to. The cloud service checks against a shared cache instead.info
Invalid links: hrefs that do not parse as a URLA malformed href is a link that goes nowhere, and javascript:void(0) is a button wearing a link costume. squirrel reports every href the parser rejected.warning
Broken anchor links: #fragments that point at nothingA link to #pricing whose target id is gone still loads, and the reader lands at the top of the page. squirrel checks every in-page anchor against the element it names.warning
Broken images: empty and placeholder src attributesAn img with an empty or placeholder src renders as a broken icon. squirrel collects image sources across the crawl and flags the malformed ones.error

How to fix it

Point each link at the URL that works now, and fix it at the source:

<a href="/guides/build-cache">Build cache guide</a>
<a href="/pricing#team-plan">Team plan</a>

The report lists every page that carries a broken link, so a link in a template is one change (the internal link fix). Where you cannot update every link, redirect the old URL permanently. Replace dead external links with a working page or an archived copy, and check unverified ones in a browser before changing them (the external link fix). Update a fragment to the id that exists now (the anchor fix), and replace a click-target anchor with a <button> (the invalid link fix).

Run the check

squirrel audit https://example.com --rule-include links/broken-links,links/broken-external-links,links/dead-links,links/invalid-links,links/broken-anchors,images/broken-images

A signed-out local audit costs nothing.

  • HTTP status code: The three-digit code a server returns with every response; 2xx success, 3xx redirect, 4xx client error, 5xx server error.
  • Fragment link: A link to an id within a page (#section); it is broken when no element on the target page carries that id.
  • Redirect chain: A sequence of two or more redirects between the requested URL and the final response.

Learn more

References

Type to search…

↑↓ navigate↵ openesc close