Dev.to WebDev 🛠 Dev 👁 0 📖 5 min read

Catching Broken Internal Links on a Law Firm Site Before Deploy

Law firm sites tend to accumulate broken internal links quietly. A charge page gets renamed, a courthouse page is merged into another, an attorney leaves and their bio is removed. The pages that linked to them keep point

Law firm sites tend to accumulate broken internal links quietly. A charge page gets renamed, a courthouse page is merged into another, an attorney leaves and their bio is removed. The pages that linked to them keep pointing at URLs that no longer exist. Nobody notices until a crawl report shows hundreds of 404s, or a visitor reading a DUI page taps "license suspension" and lands on an error.

For developers who build and maintain these sites, the cheapest fix is to stop broken links from shipping at all. If the site is built as static files, whether from a static site generator or an export from a CMS, you can check every internal link against the build output before deploy. This post covers why it matters for legal sites in particular, a small checker you can adapt, and how to fit it into a deploy pipeline.

Why broken links hurt law firm sites more than most

Defense firm sites are built around internal links. A typical structure links charge pages to court pages, court pages to process pages, and everything to attorney bios and the contact page. Those links help visitors move from "what is this charge" to "what happens at my hearing" to "who will represent me." They also help search engines understand which pages matter and how they relate.

When links break, two things happen. Visitors hit dead ends at exactly the moment they are deciding whether to call. And crawlers waste time on missing URLs while important pages lose the internal links that pointed to them. The guide to internal links that help charge pages rank explains the ranking side in more detail.

Check links against the build, not the live site

Most link checkers crawl a live site over HTTP. That works, but it finds problems after they ship. For a static build, you can do better: parse every HTML file in the output folder, collect internal links, and confirm each one maps to a file that exists.

This approach is fast, needs no server and runs the same way locally and in CI. Here is a minimal version in Python using only the standard library:

import os, sys
from html.parser import HTMLParser
from urllib.parse import urlparse, unquote

class Links(HTMLParser):
    def __init__(self):
        super().__init__(); self.hrefs = []
    def handle_starttag(self, tag, attrs):
        if tag == "a":
            href = dict(attrs).get("href")
            if href: self.hrefs.append(href)

def target(root, page, href):
    u = urlparse(href)
    if u.scheme or u.netloc or not u.path: return None
    base = "/" if u.path.startswith("/") else os.path.dirname(page)
    p = os.path.normpath(os.path.join(root, base.lstrip("/"), unquote(u.path)))
    return p if os.path.splitext(p)[1] else os.path.join(p, "index.html")

root, bad = sys.argv[1], 0
for d, _, files in os.walk(root):
    for f in files:
        if not f.endswith(".html"): continue
        page = os.path.relpath(os.path.join(d, f), root)
        parser = Links(); parser.feed(open(os.path.join(d, f), encoding="utf-8").read())
        for h in parser.hrefs:
            t = target(root, page, h)
            if t and not os.path.exists(t):
                print(f"{page}: {h}"); bad += 1
sys.exit(1 if bad else 0)

It skips external links and fragment-only links, resolves relative and root-relative paths, and treats a path without an extension as a folder with an index.html. If your host serves /page from page.html, adjust the target function to check that file too.

Handle redirects and renamed pages

Sometimes a link points to an old URL on purpose, because a redirect is in place. A strict build check will flag it. You have two choices: update the link to point directly to the new URL, or teach the checker to read your redirect file and accept redirected paths.

Updating the link is usually better. Every redirect adds a hop for visitors and crawlers, and chains of redirects build up over years of redesigns. Treat a flagged redirect as a reminder to fix the source link.

When a page is removed for good, such as a bio for a lawyer who left the firm, the checker will list every page that still links to it. That list is exactly what the content team needs to update.

Fit it into the deploy pipeline

Run the checker as a step between building and deploying. If it exits with an error, the deploy stops and the log shows each broken link with the page it came from.

A few practical notes:

  • Run it on the full build rather than the changed files alone, since a deleted page breaks links on pages that did not change.
  • Keep a short allowlist for known exceptions, with a comment explaining each one.
  • Report the count in the build log even when it is zero, so a sudden jump is easy to spot.

For a site with a few hundred pages, the check takes a second or two.

What the checker will not catch

It checks that a link resolves to a file. It does not check that the link makes sense. A link from the DUI page to the shoplifting page will pass. It also does not check anchors within pages, external links or links built by JavaScript at runtime. A periodic crawl of the live site with a full SEO crawler is still worth doing, but it should find far fewer problems.

The developer notes for law firm sites cover more technical SEO topics for people building legal websites.

Questions about checking internal links

Can this work with a CMS like WordPress?

Not directly, since WordPress builds pages on request. You can export a static copy with a crawler or a static export plugin and run the check on that, or use a crawler against a staging site before changes go live.

Should anchor links within a page be checked too?

It helps on long charge pages with a table of contents, where headings change during edits. Extend the parser to collect element IDs on each page and confirm that fragment links match one of them.

How often do broken links appear on a typical law firm site?

It depends on how often pages are renamed, merged or removed. Sites that go through redesigns, practice area changes or attorney turnover tend to collect them faster. Checking on every deploy keeps the number near zero regardless.

SBD Marketing works only with criminal defense law firms, one firm per city, and helps them with website design, SEO for the charges they defend, visibility in AI search tools and SEO audits.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.