Check 12.13 · Internal linking

Fix broken links

Repair broken internal links: 4xx and 5xx errors, missing #section anchors, malformed hrefs, deleted files, with the right replacement target.

Priority
Important
Difficulty
Easy
Estimated time
2 h to 1 day
Free, no account: your progress is saved in this browser.

Ask an AI to check this point on your site

Opens the assistant with a ready-made question: this check, its goal and your site URL.

For Gemini, Copilot or another assistant, copy the question. The link opens the chosen service directly: nothing goes through this site.

In short

A broken internal link is a link on your site that does not lead where it promises: a page returning a 404, 410 or 5xx, but also a #section anchor that no longer exists on the target page, a malformed href, a deleted PDF or image, a link that breaks only in the mobile menu or in another language. The task is to find them all, rank them by importance, then choose for each one the replacement target that keeps the link's intent. Once done, every link in your internal linking leads to the right page, at the right spot.

Detecting HTTP errors and fixing them at a basic level is covered in fix broken internal links (opens in a new tab). This guide covers what that audit misses and how to rebuild internal linking around the repaired links.

Why it matters

An internal link has two roles: taking the visitor to the answer and telling search engines which page covers the topic. A broken link loses both. Google points out that every page you care about should have a link from at least one other page on the site, and that it discovers most pages by following links; a page whose inbound links are broken becomes, from its point of view, a less connected page, or even an orphan.

Standard audits only see HTTP status codes. Yet some broken links return a 200:

  • Missing anchor: /guide-entretien/#purge-radiateurs loads the page fine, but the purge-radiateurs identifier disappeared during a rewrite. The reader lands at the top of a long guide, without the answer.
  • Malformed href: href="www.example.com/tarifs" with no protocol is read as a relative path and produces /blog/www.example.com/tarifs.
  • Link to an emptied page: the page returns a 200 but shows “No products” or an error message; see fix soft 404s (opens in a new tab).

AI assistants that browse a site, and search engines that point to a specific passage on a page, depend on the same links and the same anchors. No practice guarantees a citation, but a link that leads to the right passage can only help.

What it improves

  • Internal linking Target pages get their inbound links and the context of their anchors back.
  • Crawling Fewer requests to dead ends. A noticeable effect when the error is in a template.
  • Visitor experience Fewer error pages and fewer arrivals at the wrong spot on a long page.
  • Conversion Links from guides to commercial pages work again. Measurable in your analytics tool.
  • Rankings No direct effect; Google states that 404s do not penalize a site. The gain comes from restored internal linking.

How to check

  1. HTTP errors: a full crawl with Screaming Frog (free up to 500 URLs), Response Codes tab, Internal filter, 4xx and 5xx errors, then the Inlinks tab at the bottom for the source pages. Free methods beyond 500 URLs are in the guide fix broken internal links (opens in a new tab).
  2. #section anchors: the script in step 3.
  3. Malformed hrefs: the command in step 4.
  4. Mobile versions and languages: run the crawl again with the smartphone user agent (Configuration > User-Agent) and from the home page of each language.
  5. Bing Webmaster Tools: the Site Scan audit also reports broken links.

Compliant result: zero internal links to an error, zero missing anchors, zero malformed href values, across every version of the site.

How to implement

Step 1 — Prioritize

Export the list “source page, broken URL, anchor, link position” and add a priority:

Situation Priority
Template link (menu, footer, breadcrumbs) 1, whatever the target
Link from a high-traffic page or a page that earns backlinks 1
Link to a priority commercial page 1
Editorial link from a rarely visited page 2
Link to an old file (PDF, image) in an archive 3

Pages that receive traffic and backlinks can be found with identify the most visible pages (opens in a new tab) and identify pages that earn backlinks (opens in a new tab).

Step 2 — Choose the replacement target

A repaired link must keep the intent of the sentence. In order:

  1. The same page at its new address: replace with the exact final URL.
  2. A page that meets the same intent: a discontinued product is replaced by its successor or by the category that contains it; a merged guide by the guide that absorbed it.
  3. The parent page if it really answers the sentence: category, pillar page.
  4. None: rewrite the sentence and remove the link. Never replace with the home page by default. See avoid redirecting all removed pages to the homepage (opens in a new tab).

Adapt the anchor to the passage: if the target changes, “our 600 ml Kyusu kettle” becomes “our cast iron teapots”. For discontinued products, see manage permanently discontinued products (opens in a new tab).

Tracking table:

Source page Broken link Type New target New anchor Done on
/blog/purger-radiateurs/ /guide-entretien/#purge Missing anchor /guide-entretien/#purger-radiateurs bleed the radiators 2026-11-25
/guides/choisir-the-vert/ /products/kyusu-600 404 /collections/theieres our Japanese teapots 2026-11-25
/blog/ (footer) /blog/www.example.com/contact Href without protocol /contact/ Contact 2026-11-26

Step 3 — Repair missing #section anchors

This dependency-free Python script reads your sitemap, collects the identifiers (id and name) of each page and flags internal links whose fragment matches no identifier on the target page. Save it as ancres.py:

#!/usr/bin/env python3
"""Internal links to a #fragment anchor missing from the target page."""
import re
import sys
import time
import urllib.parse
import urllib.request
from html.parser import HTMLParser

SITEMAP = sys.argv[1]
HOST = urllib.parse.urlsplit(SITEMAP).netloc


class Parser(HTMLParser):
    def __init__(self):
        super().__init__()
        self.ids, self.links = set(), []

    def handle_starttag(self, tag, attrs):
        a = dict(attrs)
        for key in ("id", "name"):
            if a.get(key):
                self.ids.add(a[key])
        if tag == "a" and a.get("href") and "#" in a["href"]:
            self.links.append(a["href"])


def get(url):
    request = urllib.request.Request(url, headers={"User-Agent": "ancres-check/1.0"})
    with urllib.request.urlopen(request, timeout=15) as response:
        return response.read().decode("utf-8", "replace")


def urls(sitemap):
    body = get(sitemap)
    locs = re.findall(r"<loc>\s*([^<\s]+)\s*</loc>", body)
    return [u for child in locs for u in urls(child)] if "<sitemapindex" in body else locs


pages = {}
for url in urls(SITEMAP):
    try:
        parser = Parser()
        parser.feed(get(url))
        pages[url] = parser
    except Exception as error:
        print(f"# {url} : {error}", file=sys.stderr)
    time.sleep(0.3)

print("page_source\tlien\tfragment_absent")
for source, parser in pages.items():
    for href in parser.links:
        target, fragment = urllib.parse.urldefrag(urllib.parse.urljoin(source, href))
        fragment = urllib.parse.unquote(fragment)
        if not fragment or urllib.parse.urlsplit(target).netloc != HOST or fragment == "top":
            continue
        if target not in pages:
            continue
        if fragment not in pages[target].ids:
            print(f"{source}\t{href}\t{fragment}")
python3 ancres.py https://example.com/sitemap.xml > ancres-cassees.tsv

The script checks only the pages in the sitemap and does not see identifiers added by JavaScript. For each line, restore the identifier on the target page if the section still exists, or fix the link's fragment. To keep anchors from breaking every time a heading is rewritten, set stable identifiers: see add stable anchors (opens in a new tab).

Step 4 — Fix malformed hrefs

Look for the following patterns in the HTML of the main templates:

curl -s https://example.com/blog/purger-radiateurs/ \
  | grep -oE 'href="(#?|javascript:[^"]*|www\.[^"]*|https?//[^"]*|[^"/#:?][^":]*|[^"]*(undefined|null)[^"]*)"' \
  | sort | uniq -c
Pattern found Effect Fix
href="" or href="#" Reloads the page or jumps to the top A real link, or a <button> if it is an action
href="javascript:void(0)" Nothing for a bot A real <a href> link; see make links available in HTML with href (opens in a new tab)
href="www.example.com/…" Wrong relative path Full URL or root-relative path
href="produits/chaise" URL differs depending on the page /produits/chaise/
href="/undefined", /null Empty variable in the template Fix the code that builds the link

Step 5 — Fix in your tool

WordPress

Versions WordPress 6.4 to 7.1, Broken Link Checker plugin 2.4.

  • Continuous detection: the Broken Link Checker plugin checks the links in your content. With its cloud engine, offered by default, you can edit or remove them from its list; with the local engine, fix them in the editor.
  • Anchors: in the block editor, a heading's identifier is set in the block panel, Advanced > HTML anchor. Do not let it change every time the heading is edited.
  • Files: a PDF deleted from the Media Library breaks every link that points to it. When possible, replace the file with a new version at the same address rather than deleting it.
  • Menus: with a classic theme, Appearance > Menus flags items whose target page no longer exists. With a block theme, open each menu in Appearance > Editor > Navigation and check its links.

Shopify

Versions Shopify admin, all plans, November 2026.

Uploaded files (Content > Files) have an address on Shopify's CDN: a deleted file breaks the links in descriptions and pages. Menus are fixed in Content > Menus. An archived or deleted product breaks its links: replace them in blog posts and collections, and create a redirect in Content > Menus > View URL redirects for external links.

PrestaShop

Versions PrestaShop 8 and 9.

Fix the descriptions (Catalog), CMS pages (Design > Pages) and the menu and footer modules. A disabled product can return a 404 or a redirect depending on the setting chosen on its product page (SEO tab, page behavior when the product is offline): align the links with that choice.

Drupal

Versions Drupal 10 and 11, Link checker module 2.x.

The Link checker module extracts links from content when it is saved, checks them periodically and shows broken links in the reports and on the content edit page. It can also update links that point to a permanent redirect. Section identifiers are set in CKEditor through the id attribute, or with the anchor modules in your installation.

Wix

Versions Wix Editor and Wix Studio, November 2026.

Wix has no built-in link checker: start from an external crawl, then fix each link in the editor. For anchors, use the editor's “Anchor” elements and link to them rather than typing a fragment by hand.

Webflow

Versions Webflow Designer, all site plans, November 2026.

Fix the links in the Designer and in collection link fields. For an anchor, give the section an ID in the element settings panel, then choose “Page section” as the link target.

Laravel

Versions Laravel 11 to 13, Pest 3 and 4.

Add a fragment check on key pages to the internal links test:

it('contains no missing internal anchor', function (): void {
    $html = $this->get('/guide-entretien')->assertOk()->getContent();

    preg_match_all('/href="#([^"]+)"/', $html, $links);
    preg_match_all('/\sid="([^"]+)"/', $html, $ids);

    expect(array_diff(array_unique($links[1]), $ids[1]))->toBeEmpty();
});

Next.js

Versions Next.js 15 and 16.

Run linkinator on the local build in continuous integration (see the HTTP guide) and generate heading identifiers deterministically, for example with the rehype-slug plugin for MDX, so that an anchor changes only when the heading text does.

Astro

Versions Astro 5 to 7.

Astro adds identifiers to Markdown headings based on their text. A rewritten heading therefore changes its identifier: search for old fragments in src/content after each rewrite, or set the identifier in HTML within the content.

Step 6 — Monitor over time

Run the check again after every template redesign, migration or removal of a batch of products, and every month on a site that publishes often. See schedule automated crawls (opens in a new tab).

Tip: for a page that lost many inbound links at once, then check that it has not become under-linked (opens in a new tab).

Common mistakes

  • Checking only HTTP status codes: missing anchors and emptied pages slip through.
  • Replacing every broken link with the home page: the link no longer answers the sentence.
  • Keeping the original anchor with a new target: the anchor describes a page that no longer exists.
  • Rewriting a heading without checking its anchor links: every #fragment that pointed to it breaks silently.
  • Deleting a file from the media library instead of replacing it at the same address.
  • Crawling only the desktop version in a single language: mobile menus and other languages often have their own broken links. See test cross-language links (opens in a new tab).

Frequently asked questions

Updated on

Topic checklist (PDF)

And now?

In the “Internal linking” topic

  1. Identify priority commercial pages
  2. Identify pages that earn backlinks
  3. Identify the most visible pages
  4. Pass link equity to strategic pages
  5. Link complementary content (cross linking)
  6. Link articles and pillar pages in both directions (top-down and bottom-up)
  7. Link guides and commercial pages
  8. Use descriptive and varied anchor text
  9. Avoid generic anchors out of context
  10. Add contextual links
  11. Remove unnecessary links
  12. Fix links to redirects or non-canonical URLs
  13. Fix broken links
  14. Check click depth
  15. Identify under-linked pages
  16. Suggest relevant related content
  17. Audit the internal link graph
  18. Set up top-down, bottom-up and cross internal linking