Internal links to redirected URLs: updating links that take a detour

An internal link that points at a redirected URL still works, which is why these accumulate unnoticed. Each one costs visitors an extra round trip, costs crawlers an extra request, and leaves the link dependent on a redirect rule staying in place. Find them and edit the link to name the final URL directly.

This is housekeeping, not an emergency. Google follows 301s and passes signals through them. It becomes worth scheduling when the redirected links are in navigation or templates, because then every page on the site carries them.

What it looks like

Before

html
<a href="http://example.com/2019/mug-guide">our mug guide</a>

After

html
<a href="https://example.com/guides/mugs/">our mug guide</a>

How WordPress sites collect them

  • Slug changes. When you edit a post's slug, WordPress remembers the old one and redirects it, so nothing visibly breaks. (It does not do this for pages and other hierarchical types.) Links typed into other posts keep the old address indefinitely. Hydrogen SEO's Auto Redirection covers posts, pages and terms by adding a visible 301 rule.
  • Protocol and host changes. A site moved to HTTPS, or from www to the bare domain, with years of content containing absolute links in the old form.
  • Missing trailing slashes. Hand-typed links such as /about on a site whose permalinks end in a slash. WordPress redirects each one.
  • Permalink structure changes, such as removing dates or the category base from URLs.
  • Menu items saved as Custom Links. A menu item created by choosing a page updates when the page's URL changes. One created by pasting a URL does not.
  • Hard-coded links in templates, widgets and footers.

Find them

Check one page. This prints every internal link on a page whose target does not return 200:

code
page=https://example.com/blog/some-post/
curl -s "$page" | grep -oE 'href="https?://example\.com[^"#]*"' | cut -d'"' -f2 | sort -u | while read u; do
  code=$(curl -s -o /dev/null -w "%{http_code}" "$u"); [ "$code" != "200" ] && echo "$code $u"
done

Run it on the homepage first. Anything it finds there in the header or footer is site-wide.

Check from your redirect list. Every source in your redirect rules is a URL that may still be linked. In Hydrogen SEO, the list is under Hydrogen SEO → Redirections. For each source path, search your content:

code
wp db query "SELECT ID, post_title FROM wp_posts WHERE post_status='publish' AND post_content LIKE '%/2019/mug-guide%'"

Check the whole site. A crawler that reports internal links by status code will list every 3xx target with the pages linking to it. Hydrogen SEO's site audit covers the neighbouring problem, internal links that are broken outright, across the whole site.

Fix them

  1. Navigation and templates first. Edit menu items under Appearance → Menus or the Site Editor's navigation block, and replace Custom Link entries with the page itself where possible. Then footers, sidebars and reusable blocks.
  2. Single links in content. Edit the post and repoint the link at the final URL.
  3. Patterned changes in bulk. For a protocol, host or structural change that affects many posts, use WP-CLI after a database backup:
code
wp search-replace 'http://example.com/' 'https://example.com/' wp_posts wp_postmeta --dry-run
wp search-replace '/2019/mug-guide' '/guides/mugs/' wp_posts --dry-run

Review the count, then run without --dry-run. Be specific with the search string so that you do not rewrite URLs that merely start the same way. 4. Check where the redirect leads. If the final destination is not a good match for the link's anchor text, as when an old article was redirected to a category page, choose a better target for that link instead of the redirect's.

Keep the redirects after updating the links. External sites, bookmarks and Google's index still use the old addresses.

While you are in the list, note two worse cases. A link whose target redirects more than once is a redirect chain; fix both the link and the first rule so it goes straight to the end. A link whose redirect ends on the homepage, because of a blanket rule for deleted content, is effectively a broken link: Google often treats irrelevant redirects to the homepage as soft 404s. Repoint it or remove it. Our guide to fixing redirect chains covers the rule side.

Prevent new ones

  • Link to pages using the editor's link search, which inserts the current permalink, instead of pasting URLs from an old document.
  • After changing a slug, search for the old slug and update the links that week, while you remember why it changed.
  • When importing content, run a search-replace for the old domain before publishing.
  • Before deploying a batch of redirects, run the old and new URL pairs through the redirect rule generator, which warns about chains within the list.

Run the one-page check again on the homepage and on two or three heavily linked posts; it should print nothing. Hydrogen SEO's internal link counter will show the link counts for the final URLs rising, since links that previously named the old address now name the page itself. The free SEO audit counts the internal links on a page and reports links that fail outright; redirected links are not flagged there, so use the loop above.

Common questions

Do internal redirects lose link equity?

Google has said 301 redirects pass signals to the destination. The reasons to fix them are speed, crawl efficiency and not depending on redirect rules that might be removed later.

Should I delete the redirect once the links are updated?

No. Other sites, bookmarks and search results still point at the old URL.

Are redirected links worse than broken links?

No. A broken link fails; a redirected one arrives late. Fix broken links first.

Does WordPress update internal links when I change a slug?

No. It redirects the old slug to the new one, but links stored in the content of other posts keep the old address until you edit them.