Check 12.12 · Internal linking

Fix links to redirects or non-canonical URLs

Find internal links that go through a redirect or target a URL canonicalized elsewhere, and fix them at the source: CMS, theme or code.

Priority
Important
Difficulty
Intermediate
Estimated time
2 h to 2 days
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

An internal link should point directly to the page's final, canonical URL: the one that returns a 200 and whose canonical tag points to itself. Yet many sites link to http:// instead of https://, an address without a trailing slash that redirects, an old slug, a URL with tracking parameters or a variant canonicalized to another page. The task is to find these links, work out where they come from (template, content, CMS setting) and fix them at the source. Once done, a crawl no longer finds any internal link to a redirect or to a page canonicalized elsewhere.

Why it matters

Google says so in its documentation on consolidating duplicates: when linking within your site, link to the canonical URL rather than a duplicate URL, because consistent links help it understand your preference. A link to a variant sends the opposite signal to your canonical; if many links repeat it, Google may pick a different URL from the one you chose.

A link to a redirect works, but it has a cost: one more request for every bot and every visitor, one more network round trip before the page displays, and sometimes a chain when the target has itself been moved. Google recommends avoiding long redirect chains, which hurt crawling, and, when URLs change, updating internal links to the old addresses.

Redirects remain useful, but for everyone else: external sites, bookmarks, old emails. Your own links are yours to fix.

What it improves

  • Choice of canonical Every link confirms the URL you declare. See align canonicals, sitemap and internal links (opens in a new tab).
  • Crawling Fewer requests to redirects and duplicates. A noticeable effect on large sites.
  • Speed Every click avoids a redirect round trip.
  • Measurement Without utm_ parameters on internal links, your own links no longer overwrite the traffic source of visits.
  • Rankings An indirect effect. The gain comes from cleaner signals, not from “link equity lost” in the redirect.

How to check

With Screaming Frog (free up to 500 URLs):

  1. Start the crawl from the home page's canonical URL.
  2. Response Codes tab, Internal filter, then the redirects (Redirection (3xx)): these are the redirected URLs your pages link to. To get each link with its source page and anchor: Bulk Export > Response Codes > Internal > Redirection (3xx) Inlinks.
  3. Canonicals tab, Canonicalised filter: pages that point to another URL. Select one, then the Inlinks tab at the bottom: every link listed targets a non-canonical URL.
  4. URL tab, Uppercase and Parameters filters: they find links to uppercase variants or variants with parameters.

On one page, from the command line: this script lists a page's internal links that do not return a 200 directly.

SITE="https://example.com"
PAGE="$SITE/"
curl -s "$PAGE" \
  | grep -oE 'href="(/|https?://(www\.)?example\.com)[^"#]*"' \
  | sed -E 's/^href="//; s/"$//' | sort -u \
  | while read -r url; do
      case "$url" in /*) url="$SITE$url" ;; esac
      code=$(curl -s -o /dev/null -w '%{http_code} %{redirect_url}' "$url")
      case "$code" in 200*) ;; *) echo "$code <- $url" ;; esac
    done

Compliant result: no output. A line such as 301 https://example.com/tarifs/ <- https://example.com/tarifs flags a link without a trailing slash.

Across the whole site without a paid tool: the Python script in the guide align canonicals, sitemap and internal links (opens in a new tab) flags each LINK_TO_REDIRECT with its source page.

How to implement

Before you start

Settle on the reference form of your URLs: https, with or without www, trailing slash or not, lowercase, no tracking parameters. See standardize HTTP/HTTPS and www/non-www (opens in a new tab) and standardize letter case and trailing slashes (opens in a new tab). Then sort the faulty links by cause, because each cause is fixed in a different place:

Cause Link example Final URL Where to fix
Protocol http://example.com/tarifs/ https://example.com/tarifs/ Content (bulk replace)
Host https://www.example.com/… https://example.com/… Content, site URL setting
Trailing slash /tarifs /tarifs/ Template, menus, links typed by hand
Old slug /offres/pack-pro/ /tarifs/ Content and menus
Tracking parameters /tarifs/?utm_source=blog /tarifs/ Content, internal banners
Canonicalized variant /collections/the-vert/products/sencha /products/sencha Theme
Pagination page 1 /blog/?page=1 /blog/ Pagination component
Index file /index.php, /accueil.html / Logo, menu

Good to know: do not remove the redirects once the links are fixed. They remain useful for external links, bookmarks and bots that know the old addresses. See use 301/308 for permanent moves (opens in a new tab).

Apache

Versions Apache 2.4.

The server does not fix links, but its logs show the ones visitors and bots actually follow: a redirect whose referrer is a page on your domain is an internal link to fix. For the combined log format:

awk '($9 == 301 || $9 == 302 || $9 == 307 || $9 == 308) && $11 ~ /example\.com/ {print $11, $7}' /var/log/apache2/access.log \
  | sort | uniq -c | sort -rn | head -n 50

The first column counts the hits, the second gives the source page, the third the redirected URL.

Nginx

Versions Nginx 1.18 and later.

Same command on /var/log/nginx/access.log. If the logs are sent to an external service, filter the 3xx codes whose referrer belongs to your domain.

Cloudflare

Versions Cloudflare dashboard, all plans, November 2026.

Redirects performed at the edge (Always Use HTTPS, redirect rules, in the rules overview) hide the problem without solving it: the http:// link still costs a redirect, just a faster one. Keep these rules as a safety net and fix the links on the site. Cloudflare's logs, when your plan gives access to them, allow the same filtering as in the Apache section.

WordPress

Versions WordPress 6.4 to 7.1, WP-CLI 2, Redirection plugin 5.

  • Links in content: after a backup, bulk-replace the old form with the new one using WP-CLI, starting with a dry run:
wp search-replace 'http://example.com' 'https://example.com' --skip-columns=guid --dry-run
wp search-replace 'http://example.com' 'https://example.com' --skip-columns=guid
wp search-replace 'https://example.com/offres/pack-pro/' 'https://example.com/tarifs/' --skip-columns=guid

The Better Search Replace plugin does the same from the admin.

  • Menus: Appearance > Menus (or Appearance > Editor > Navigation). “Custom Links” items keep the URL that was typed: replace them with Page or Category items, which follow slug changes.
  • Trailing slash: Settings > Permalinks sets the form of generated URLs. Links typed by hand in content must follow the same form.
  • Site settings: in Settings > General, “WordPress Address (URL)” and “Site Address (URL)” must use the reference form (https, correct host).
  • Detection: the Redirection plugin logs the redirects served along with their referrer, which reveals the pages that still link to old URLs.

Shopify

Versions Online Store 2.0 themes, all Shopify plans, November 2026.

  • Product links in collections: some themes build grid links with the Liquid within filter, which produces /collections/the-vert/products/sencha-ariake. Shopify points out that these URLs carry the same content as /products/sencha-ariake. In Online Store > Themes > Edit code, look for within: collection in the product card snippets and replace:
<a href="{{ product.url | within: collection }}">{{ product.title }}</a>

with:

<a href="{{ product.url }}">{{ product.title }}</a>
  • Menus and descriptions: Content > Menus and the product, collection, page and blog post editors. After a URL handle change, Shopify can create the redirect, but replace the links as well.
  • Variants: a link with ?variant= targets a URL canonicalized to the product. Keep it where it helps the purchase (color selection), not in editorial links.

PrestaShop

Versions PrestaShop 8 and 9.

In Shop Parameters > Traffic & SEO, check that friendly URLs are enabled and that the redirect to the canonical URL option is set to 301. Then fix the links hard-coded in descriptions (Catalog), CMS pages (Design > Pages) and the menu and footer modules.

Magento

Versions Magento Open Source and Adobe Commerce 2.4.

In Stores > Settings > Configuration > Catalog > Catalog > Search Engine Optimization, two settings decide the form of product links: “Use Categories Path for Product URLs” (set to No, lists link to the product's short URL) and “Use Canonical Link Meta Tag For Products” (set to Yes). If categories appear in product URLs, list links target canonicalized variants: align the two settings, then flush the cache.

Laravel

Versions Laravel 10 to 13.

  • A single source of URLs: generate links with route() or url(), never hard-coded. Set APP_URL to the reference form in .env.
  • Trailing slash: Laravel routes are written without a trailing slash, and, under Apache, the .htaccess file shipped in public/ redirects (308) URLs with a trailing slash to their form without one. So do not type /tarifs/ in content.
  • Behind a proxy or a CDN, configure trusted proxies so that Laravel generates https links. Only the location of this setting changes between versions. Failing that, force the scheme in AppServiceProvider:
use Illuminate\Support\Facades\URL;

public function boot(): void
{
    if ($this->app->environment('production')) {
        URL::forceScheme('https');
    }
}

Laravel 11 to 13

Trusted proxies are declared in bootstrap/app.php:

->withMiddleware(function (Middleware $middleware): void {
    $middleware->trustProxies(at: '*');
})

Replace '*' with the addresses of your proxy or load balancer when you know them.

Laravel 10

Trusted proxies are declared in the app/Http/Middleware/TrustProxies.php middleware, $proxies property:

protected $proxies = '*';

Next.js

Versions Next.js 15 and 16.

The trailingSlash option in next.config.js (or next.config.ts) sets the URL form; the href values of your Link components must follow it. After a rename declared in redirects(), search for the old path in the code and content:

grep -rn --include='*.tsx' --include='*.mdx' --include='*.md' '/offres/pack-pro' app content

Astro

Versions Astro 5 to 7.

The trailingSlash option in astro.config.mjs defaults to ignore. Set it to always or never according to your reference form, so that discrepancies become visible during development, then align the links in components and Markdown content.

Preventing the problem from coming back

Add an automated check after each deployment: the script from the “How to check” section on the main templates, or a scheduled crawl. See schedule automated crawls (opens in a new tab).

Common mistakes

  • Relying on the redirect: it catches visitors, it does not replace a correct link.
  • Fixing content and forgetting the template: a logo pointing to /index.php is repeated on every page.
  • Adding utm_ parameters to internal links to measure a banner: use a click event in your analytics tool instead.
  • Bulk replacing without a dry run: an overly broad pattern can hit external URLs or serialized data.
  • Removing redirects after the fix: external links and bookmarks then end up on a 404.
  • Leaving two valid URL forms returning a 200: with no redirect or canonical, every wrong link creates an indexable duplicate.

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