Sub topic 12
Update internal links to the surviving URL
After a merge, the old URLs return 301 redirects, and those redirects keep working. Internal links that still point at the old URLs are a different matter. Each one sends visitors and crawlers through an extra hop, and each one tells search engines that the old URL is still the page you care about. This chapter covers how to find those links, which ones to change, and how to check the result.
It assumes you have already merged the pages and set up the redirects from the previous chapters. It also assumes you can export a crawl or the site's HTML and read simple Python.
Why redirects are not enough
A 301 redirect passes most signals from the old URL to the new one. Google has said that links through a 301 do not lose ranking power in the way they once did. That does not make leaving them in place a good plan, for four reasons.
- Extra request. Every click on an old link costs a round trip before the real page loads. Crawlers also spend part of their crawl budget following the hop.
- Mixed signals. If your own pages keep linking to the retired URL, you are telling search engines that it is still part of the site structure. The surviving URL should receive the links you control.
- Fragile chains. Redirects get removed during server migrations, CMS changes, or cleanups. A link that points straight at the live page keeps working when that happens.
- Chains and loops. If the old URL was already redirecting somewhere else, a new merge can produce a chain (A to B to C). Google follows only a limited number of hops, and every hop slows the page down.
Internal links are the one link source you fully control. Updating them is cheap compared to the benefit.
Find every link to the old URLs
Start with a list of the retired URLs. You should already have it from your redirect map. Then look for links to those URLs in every place they can appear.
| Location | How to find it | Notes |
|---|---|---|
| Body content | Site crawl, CMS search, database query | The most common source and the most valuable to fix |
| Navigation menus | CMS menu editor | One change affects every page |
| Footer and sidebar widgets | Theme or template files | Often forgotten because they are not in the post editor |
| Breadcrumbs | Template code | May hold a hard-coded old category URL |
| Related-post modules | Plugin settings | Some store links as manual selections |
| HTML sitemap pages | The page itself | Separate from the XML sitemap |
| Structured data | View source, Rich Results Test | URLs inside `url`, `mainEntityOfPage`, or breadcrumb markup |
| Canonical and hreflang tags | View source | Must name the surviving URL, never the old one |
| RSS or Atom feeds | Feed output | Often generated from the same stale permalinks |
A site crawler is the fastest tool for the full picture. Crawl the site, then filter the link report for "inlinks" whose destination is one of the old URLs. Most crawlers can also export "redirect chains" and "pages that link to a redirect," which are the same reports under different names.
If you have the rendered HTML (for example from a static-site build or a crawl export), you can check it with a short script. The script below reads a folder of exported HTML files, resolves each link against the page's own URL, and reports links that point at a retired path.
from html.parser import HTMLParser
from pathlib import Path
from urllib.parse import urljoin, urlparse
SITE = "https://example.com"
OLD_PATHS = {"/blog/on-page-seo-basics/", "/blog/seo-tips-2019/"}
NEW_PATH = "/guides/seo-checklist/"
class LinkCollector(HTMLParser):
def __init__(self, page_url):
super().__init__()
self.page_url = page_url
self.links = [] # list of (absolute_url, anchor_text)
self._href = None
self._text = []
def handle_starttag(self, tag, attrs):
if tag == "a":
href = dict(attrs).get("href")
if href:
self._href = urljoin(self.page_url, href)
self._text = []
def handle_data(self, data):
if self._href is not None:
self._text.append(data)
def handle_endtag(self, tag):
if tag == "a" and self._href is not None:
self.links.append((self._href, " ".join("".join(self._text).split())))
self._href = None
def normalize(path):
return path.rstrip("/") + "/"
root = Path("site_export")
site_host = urlparse(SITE).netloc
for html_file in sorted(root.rglob("*.html")):
rel = html_file.relative_to(root).as_posix()
if rel.endswith("index.html"):
rel = rel[: -len("index.html")]
page_url = f"{SITE}/{rel}"
parser = LinkCollector(page_url)
parser.feed(html_file.read_text(encoding="utf-8"))
for url, anchor in parser.links:
parsed = urlparse(url)
if parsed.netloc == site_host and normalize(parsed.path) in OLD_PATHS:
print(f"{page_url}\n links to {parsed.path} anchor: {anchor!r}")
print(f" change to {NEW_PATH}")The script prints the anchor text next to each hit. You need it for the next step.
Rewrite the links, not only the URLs
Replacing the href is the minimum. Read the anchor text and the sentence around it before you commit the change.
Suppose a post says "see our [2019 SEO tips](/blog/seo-tips-2019/)". The merged page is now a current checklist. If you only swap the URL, the link text promises something the destination no longer is. Change it to something like "see our [SEO checklist](/guides/seo-checklist/)". Anchor text is one of the clearest hints about what the target page covers, so it should describe the surviving page.
Some practical rules:
- Use descriptive anchor text that matches the topic of the surviving page. Avoid "click here."
- If one page contained two links to two different old URLs that now go to the same place, keep one and remove the duplicate. Two adjacent links to the same URL add nothing.
- Keep any fragment (
#section-name) only if that heading still exists on the merged page. If the old content became a section, point to its new heading ID. - Use root-relative or absolute URLs that match your canonical form: same protocol, host, and trailing-slash style as the redirect target. A link to
http://or to a non-preferred host creates another redirect. - Do not edit links in user comments or in quoted material where the text must stay as written. Leave those to the redirect.
Prioritize by value. Fix the navigation, the footer, and the pages with the most traffic or the most inbound links first. A search-and-replace in the database is fine for exact URL strings, but run it on a backup copy first and review a sample of the changes. Blind replacement can damage URLs that merely contain the old path as a prefix.
Check that the surviving page is well linked
Consolidation concentrates the value of several pages in one. The surviving page should therefore be easy to reach from the places where the old pages were linked, and it should link out sensibly itself.
- Confirm that every page which linked to any of the old URLs now links to the surviving one.
- Add links from closely related pages that never linked to the old ones, if they are relevant to readers.
- Check the merged page's own outbound links. Content copied from the old pages may bring links that point at other retired URLs.
- Make sure the page is reachable within a few clicks from the home page or a hub page, not only through the sitemap.
<br>
Verify the result
Recrawl the site after the edits. A clean result has these properties:
- The crawler reports zero internal links to the retired URLs.
- No internal link points to a URL that returns a 3xx status. Filter the crawl for "internal redirects" and check that the list is empty or contains only intentional entries.
- The surviving URL shows an increase in internal inlinks compared with the earlier crawl.
- The surviving page's canonical tag points to itself.
Keep the 301 redirects in place after the links are fixed. External sites, bookmarks, and old search results still use the old URLs, and the redirects are what serve them.
Common mistakes
- Fixing only the body text. Menus, breadcrumbs, and schema markup keep sending signals to the old URL.
- Pointing links at a redirecting URL on purpose. A link to a URL that redirects to a second URL that redirects to a third creates a chain. Always link to the final destination.
- Keeping the old anchor text. The link then describes a page that no longer exists.
- Ignoring the XML sitemap. The sitemap should list only the surviving URL. The next chapters cover sitemap updates and recrawl requests.
Exercise
A crawl after a merge shows that 40 blog posts still link to /blog/seo-tips-2019/, which now redirects with a 301 to /guides/seo-checklist/. A colleague says the links can stay because the redirect passes link equity. Give two reasons to update them anyway, and say what else you should check besides the href value.
Show answer
Reasons: each click and crawl needs an extra redirect hop, and the links keep signalling that the retired URL is still part of the site; they also break if the redirect is removed later. Also check the anchor text, since it may still describe the old 2019 article instead of the checklist, and check any fragment identifier, since the heading it refers to may not exist on the merged page. After editing, recrawl to confirm no internal links to the old URL or to any redirecting URL remain.