Sub topic 13
Auditing Slugs and Internal Links
This chapter assumes you know how crawlers discover pages through links and how a 301 redirect works. It also assumes you can read basic Python and know what a canonical tag is. Earlier chapters covered how to write slugs, link pages and choose anchor text. This chapter checks whether a real site still follows those rules.
What an audit is for
A site drifts over time. Editors rename pages, authors paste generic links, and old posts stop being linked. An audit finds that drift by comparing the site's actual state with the rules you set. It answers six questions:
- Which internal links point to pages that return 404 or another error?
- Which links go through a redirect, and which go through a chain of redirects?
- Which pages have no internal links pointing to them (orphans)?
- Which important pages sit too many clicks from the home page?
- Which links use generic or repeated anchor text?
- Which URLs break your slug rules or exist in several versions?
The audit workflow
Every audit follows the same steps. You collect the site's URLs and links, build a link graph, run checks over the graph, then fix issues in priority order and crawl again.
Collecting the data
Use two sources, because each one hides something the other shows.
- A crawl starting at the home page. It follows only links, as a search engine does. Any page the crawl does not reach has no usable internal path to it.
- A list of known URLs. Take it from the XML sitemap, the CMS database, analytics, or Search Console. Compare it with the crawl. A URL that is on this list but missing from the crawl is an orphan.
Configure the crawler to record the HTTP status of every URL, the redirect target, the canonical URL, and each link's href and anchor text. Most crawling tools export these. The script below works on the same data.
What each check looks for
| Check | Problem signal | Usual fix |
|---|---|---|
| Broken link | Link target returns 404 or 410 | Update the link, or restore the page |
| Redirected link | Link target returns 301 | Change the `href` to the final URL |
| Redirect chain | More than one redirect before a 200 | Point the first redirect at the final URL and update links |
| Redirect loop | A redirect sequence returns to an earlier URL | Fix the server rules |
| Orphan page | Indexable page with zero inbound internal links | Link it from a relevant hub or retire it |
| Deep page | Important page more than 3 clicks from home | Link it from a hub closer to the top |
| Generic anchor | "click here", "read more", bare URL | Rewrite the anchor to describe the target |
| Slug rule break | Uppercase, underscores, encoded characters, years, long slugs | Rename with a 301 from the old URL |
| Canonical conflict | Links point to a URL whose canonical is a different URL | Link to the canonical version |
Redirected links still work for visitors, so they are less urgent than broken links. They cost an extra request on every visit. Google follows several redirect hops, but each hop adds delay and another place for the chain to break.
A runnable audit script
The script audits a small site model held in a dictionary, so it runs without network access. In a real audit, you would fill the same structure from your crawler's export. The script resolves redirects, flags problems, and finds orphans and click depth with a breadth-first search from the home page.
import re
from collections import deque, defaultdict
GENERIC = {"click here", "here", "read more", "learn more", "more", "this page", "link"}
SITE = {
"/": {"status": 200, "links": [
("/guides/", "SEO guides"),
("/blog/seo-tips-2019", "click here"),
]},
"/guides/": {"status": 200, "links": [
("/guides/url-slugs/", "guide to writing URL slugs"),
("/missing/", "an old page"),
("/Blog/Link_Building_Guide", "link building guide"),
]},
"/guides/url-slugs/": {"status": 200, "links": [("/guides/", "all guides")]},
"/blog/seo-tips-2019": {"status": 301, "location": "/blog/internal-linking-tips"},
"/blog/internal-linking-tips": {"status": 301, "location": "/blog/internal-links"},
"/blog/internal-links": {"status": 200, "links": []},
"/Blog/Link_Building_Guide": {"status": 200, "links": []},
"/old-orphan/": {"status": 200, "links": []},
"/missing/": {"status": 404},
}
def resolve(site, url, limit=10):
"""Follow redirects. Return (final_url, hops); final_url is None on a loop."""
hops = [url]
while site.get(url, {}).get("status") in (301, 302):
url = site[url]["location"]
if url in hops or len(hops) >= limit:
hops.append(url)
return None, hops
hops.append(url)
return url, hops
def slug_problems(path):
problems = []
slug = path.rstrip("/").rsplit("/", 1)[-1]
if not slug:
return problems
if path != path.lower():
problems.append("uppercase")
if "_" in path:
problems.append("underscore")
if "%" in slug or not slug.isascii():
problems.append("encoded or non-ASCII characters")
if "--" in slug:
problems.append("double hyphen")
if len(slug) > 60:
problems.append("longer than 60 characters")
if re.search(r"(?<!\d)(?:19|20)\d{2}(?!\d)", slug):
problems.append("contains a year")
return problems
def audit(site, home="/"):
for src, page in site.items():
if page.get("status") != 200:
continue
for href, anchor in page.get("links", []):
final, hops = resolve(site, href)
if final is None:
print("Redirect loop:", " -> ".join(hops))
continue
if len(hops) > 2:
print("Redirect chain:", src, "->", " -> ".join(hops))
elif len(hops) == 2:
print(f"Redirected link: {src} -> {href} (use {final})")
status = site.get(final, {}).get("status", 404)
if status != 200:
print(f"Broken link: {src} -> {final} ({status})")
if anchor.strip().lower() in GENERIC:
print(f'Generic anchor: {src} links to {href} with "{anchor}"')
for url, page in site.items():
if page.get("status") == 200:
problems = slug_problems(url)
if problems:
print(f"Slug: {url}: " + ", ".join(problems))
depth = {home: 0}
queue = deque([home])
while queue:
current = queue.popleft()
for href, _ in site[current].get("links", []):
final, _ = resolve(site, href)
if final and site.get(final, {}).get("status") == 200 and final not in depth:
depth[final] = depth[current] + 1
queue.append(final)
for url, page in site.items():
if page.get("status") == 200 and url not in depth:
print("Orphan:", url)
by_depth = defaultdict(list)
for url, d in depth.items():
by_depth[d].append(url)
for d in sorted(by_depth):
print(f"Depth {d}: " + ", ".join(sorted(by_depth[d])))
audit(SITE)Running it prints:
Redirect chain: / -> /blog/seo-tips-2019 -> /blog/internal-linking-tips -> /blog/internal-links
Generic anchor: / links to /blog/seo-tips-2019 with "click here"
Broken link: /guides/ -> /missing/ (404)
Slug: /Blog/Link_Building_Guide: uppercase, underscore
Orphan: /old-orphan/
Depth 0: /
Depth 1: /blog/internal-links, /guides/
Depth 2: /Blog/Link_Building_Guide, /guides/url-slugs/The home page link to /blog/seo-tips-2019 shows how problems stack up. The page is reached through two redirects, the anchor says nothing about the target, and the slug contains a year. One fix handles all three. Change the link to /blog/internal-links and use anchor text that names the topic.
Reading the results
Fix the cause, not each symptom
A broken link may appear on 400 pages because it sits in a footer or template. Fix the template once. Group findings by the source that generates them (template, navigation, article body) and by the target URL. Then fix the groups with the most links first.
Redirects: fix links, keep the redirect
After you update a link to the final URL, leave the 301 in place. External sites, bookmarks and search results still use the old address. Delete a redirect only when logs show almost no traffic to the old URL and no inbound links remain.
Orphans need a decision
Not every orphan is a mistake. Check each one and choose one of four outcomes:
- The page should rank, so link it from a relevant hub and from related pages.
- The page is obsolete, so redirect it to the closest replacement or return 410.
- The page is a duplicate, so point its canonical tag at the main version.
- The page is intentionally private or
noindex, so leave it alone.
A page listed in the sitemap but with no internal links is a weak signal. The sitemap helps discovery, but the lack of links tells search engines the site does not consider the page important.
Depth is relative
Three clicks is a guideline, not a limit. A large catalog may need deeper levels. The useful check is whether your most important pages are close to the home page, not whether every page is. Pagination is a common cause of deep pages. Item 200 in a list may be 20 clicks deep unless category pages, filters or related links give it a shorter path.
Edge cases that fool audits
- Links added by JavaScript. A crawler that does not render pages will miss them and report false orphans. Compare a plain HTML crawl with a rendered crawl.
- Trailing slash and case variants.
/guides/url-slugsand/guides/url-slugs/count as separate URLs unless one redirects to the other. Normalize URLs before you build the graph, or you will count duplicates as distinct pages. - Query parameters. Tracking parameters create many URLs for one page. Strip known tracking parameters before analysis, and check that each variant has a canonical tag pointing to the clean URL.
- Links to non-canonical URLs. If
/shoes/?color=redhas a canonical tag pointing to/shoes/, internal links should point to/shoes/. Conflicting signals make the canonical tag less reliable. nofollowand similar attributes. A link withrel="nofollow"may not pass the signals you expect. Recordrelvalues in your export so you can tell which internal links are affected.- Anchor repetition. Many pages linking to one target with exactly the same keyword phrase can look unnatural. Aim for descriptive wording that varies with context.
- Redirects that hide the real status. A broken page that redirects to the home page can look healthy in a crawl. Treat redirects to unrelated pages as a possible soft 404.
Setting a routine
Run a full audit before and after any site migration, redesign or bulk slug change. Run a lighter check on a schedule, such as monthly, for new broken links, new orphans and new redirect chains. Save each report so you can see whether the counts go up or down. Put the cheapest checks into your publishing process, for example a build step that fails when a new page uses an uppercase slug or links to a 404.
Exercise
A crawl shows 350 pages linking to /blog/seo-tips-2019, which returns a 301 to /blog/internal-linking-tips, which returns a 301 to /blog/internal-links, which returns 200. What do you change, and what do you leave alone?
Show answer
Change the 350 links, probably by fixing the template or navigation that generates most of them, so they point directly to /blog/internal-links. Update the first redirect so /blog/seo-tips-2019 also goes straight to /blog/internal-links. Leave both redirects in place so old external links and bookmarks still work.
Exercise
Your crawl finds 40 pages with no inbound internal links, but all 40 are listed in the sitemap. A teammate says the sitemap is enough. What do you do?
Show answer
Review the pages in groups. Link the ones that should rank from relevant hubs and related pages. Redirect or remove obsolete ones, and canonicalize duplicates. Leave intentionally private pages alone. The sitemap helps discovery, but a page with no internal links gets none of the importance signals a link provides.
Exercise
An audit run on a plain HTML crawl reports that the whole "Reviews" section is orphaned. The links to it are added by a JavaScript menu. What do you do before changing anything?
Show answer
Re-crawl with JavaScript rendering and compare. If the links appear, the pages are not orphans in the rendered view. Then decide whether to also provide the links in the server-sent HTML as ordinary a elements with href attributes, since that is the most reliable way for crawlers to find them.