# Check canonicals, hreflang, sitemaps and robots.txt

- Check 44.16 · Redesign and migration · Critical
- Source: https://checklist-seo-geo.com/en/redesign-migration/check-canonicals-hreflang-sitemaps-robotstxt
- Check before and after the switchover that canonical, hreflang, sitemaps and robots.txt target the new live URLs, with a free script and fixes per CMS.
- Updated on 2026-11-25
- Licence: CC BY 4.0. Credit “Checklist SEO & GEO” with a link to https://checklist-seo-geo.com/en/redesign-migration/check-canonicals-hreflang-sitemaps-robotstxt.
- Plugin checklist-seo-geo: 1.3.1 · https://github.com/maximegaul/checklist-seo-geo

## In short

After a redesign, four files or tags tell search engines which URLs count: the `canonical` tag, the `hreflang` annotations, the XML sitemaps and the `robots.txt` file. The task consists of checking, on staging and then on the live site on switchover day, that they all point to the new production URLs, returning `200` and indexable, and never to the old domain or to staging. The deliverable is a per-URL check table with no anomalies.

## Why it matters

These signals are generated by the CMS or framework from a site address setting. During development, that setting holds the staging address; at switchover, it must change everywhere, including in the scheduled tasks that produce the sitemaps. A single oversight is enough for the whole site to declare a canonical pointing to `staging.example.com`, or for the sitemap to still list the old URLs.

For a site move, Google explicitly asks that the new site's canonicals use the new URLs, that hreflang annotations be updated and that sitemaps list the new addresses. It also reminds you to remove the `noindex` and `robots.txt` blocks that were only needed during the migration.

These signals are hints, not directives: when they contradict each other (canonical to A, sitemap to B, links to C), Google chooses the canonical URL itself, and not necessarily the one you want. Bing, on which Microsoft Copilot and other assistants partly rely, reads the same signals.

## What it improves

- **Carrying rankings over**: the signals converge on the new URLs, which speeds up the replacement of the old ones in the index.
- **Indexing**: no pages excluded because of a canonical pointing to a redirected, non-existent or blocked URL.
- **Multilingual sites**: the right language version is still served in each country.
- **Crawling**: crawlers discover the new URLs through the sitemap instead of having to look for them.
- **Visibility in generative engines**: indirect. Assistants that rely on Google's or Bing's index cite the URLs those engines have selected as canonical.

## How to check

Quick check on one page:

```bash
curl -s https://example.com/tarifs/ | grep -i -E '<link[^>]+rel="(canonical|alternate)"|<meta[^>]+name="robots"'
curl -sI https://example.com/tarifs/ | grep -i x-robots-tag
curl -s https://example.com/robots.txt
```

Correct result: an absolute canonical identical to the requested URL, `hreflang` values as absolute URLs on the new site, no `noindex`, and a `robots.txt` with no site-wide `Disallow: /` whose `Sitemap:` lines point to the new domain.

In Search Console, the [robots.txt report](https://search.google.com/search-console/settings/robots-txt) shows the version Google fetched and its date; the [URL Inspection tool](https://search.google.com/search-console?action=inspect) shows, for an indexed page, the user-declared canonical and the one selected by Google. In Bing Webmaster Tools, the [robots.txt Tester](https://www.bing.com/webmasters/robotstxttester) does the same check for Bingbot.

## How to implement

### Before you start

Run this check twice: on staging a few days before the switchover, then on the live site within the hour that follows. Keep the [redirect map](https://checklist-seo-geo.com/en/redesign-migration/create-comprehensive-redirect-map) and the [crawl of the old site](https://checklist-seo-geo.com/en/redesign-migration/crawl-site-before-redesign) to hand.

Checklist to reproduce in a spreadsheet:

| Signal | Correct | Typical anomaly after a redesign |
|---|---|---|
| `robots.txt` | Intended rules for the new site, `Sitemap:` lines pointing to the new domain | `Disallow: /` inherited from staging, sitemap on the old domain |
| Canonical | Absolute, self-referencing on indexable pages, on the production domain | Staging, old domain, `http://`, redirected URL |
| Hreflang | Reciprocal, self-referencing, targets returning `200` on the new domain | Old URLs, missing language, target returning `404` |
| Sitemaps | New URLs only, returning `200`, indexable and canonical | Old URLs, staging URLs, `noindex` pages |

### Step 1 — Check robots.txt

Compare the production `robots.txt` with the old site's: blocked directories have often been renamed (`/panier` becomes `/cart`). Check that no resource needed for rendering (CSS, JavaScript, images) is blocked and that each `Sitemap:` line uses an absolute URL on the new domain.

```txt
User-agent: *
Disallow: /cart
Disallow: /checkout
Disallow: /recherche

Sitemap: https://example.com/sitemap.xml
```

If you manage access for AI crawlers, carry over the per-crawler rule groups (`OAI-SearchBot`, `Claude-SearchBot`, `PerplexityBot`…) from the old file: see [configure robots.txt to match these goals](https://checklist-seo-geo.com/en/ai-crawler-access-data-policy/configure-robotstxt-match-these-goals).

> **Good to know:** Google generally caches `robots.txt` for up to 24 hours. After a fix, request a recrawl from the Search Console robots.txt report.

### Step 2 — Run the check script

This dependency-free Python script reads the sitemap (or sitemap index), requests each URL without following redirects and flags anomalies. Pass it as arguments the hosts that must not appear anywhere: staging and the old domain.

```python
# Usage: python3 controler-signaux.py https://example.com/sitemap.xml staging.example.com ancien-domaine.fr > controle.csv
import csv
import gzip
import sys
import urllib.error
import urllib.request
import xml.etree.ElementTree as ET
from html.parser import HTMLParser
from urllib.parse import urlparse

NS = '{http://www.sitemaps.org/schemas/sitemap/0.9}'
UA = 'Mozilla/5.0 (compatible; controle-migration)'
LIMITE = 2000


class SansRedirection(urllib.request.HTTPRedirectHandler):
    def redirect_request(self, *args, **kwargs):
        return None


ouvreur = urllib.request.build_opener(SansRedirection)


def lire(url):
    requete = urllib.request.Request(url, headers={'User-Agent': UA})

    try:
        reponse = ouvreur.open(requete, timeout=30)
    except urllib.error.HTTPError as erreur:
        return erreur.code, erreur.headers, b''

    corps = reponse.read()

    if corps[:2] == b'\x1f\x8b':
        corps = gzip.decompress(corps)

    return reponse.status, reponse.headers, corps


def urls_du_sitemap(url):
    requete = urllib.request.Request(url, headers={'User-Agent': UA})
    corps = urllib.request.urlopen(requete, timeout=30).read()

    if corps[:2] == b'\x1f\x8b':
        corps = gzip.decompress(corps)

    racine = ET.fromstring(corps)

    if racine.tag == f'{NS}sitemapindex':
        for loc in racine.iter(f'{NS}loc'):
            yield from urls_du_sitemap(loc.text.strip())

        return

    for loc in racine.iter(f'{NS}loc'):
        yield loc.text.strip()


def normaliser(url):
    return url if urlparse(url).path else f'{url}/'


class Balises(HTMLParser):
    def __init__(self):
        super().__init__()
        self.robots = ''
        self.canonical = ''
        self.hreflang = []

    def handle_starttag(self, tag, attrs):
        a = {k: (v or '') for k, v in attrs}
        rel = a.get('rel', '').lower()

        if tag == 'meta' and a.get('name', '').lower() == 'robots':
            self.robots = a.get('content', '')

        if tag == 'link' and rel == 'canonical':
            self.canonical = a.get('href', '')

        if tag == 'link' and rel == 'alternate' and a.get('hreflang'):
            self.hreflang.append(a.get('href', ''))


sitemap = sys.argv[1]
hotes_interdits = sys.argv[2:]
hote = urlparse(sitemap).netloc
sortie = csv.writer(sys.stdout)
sortie.writerow(['url', 'code', 'x_robots_tag', 'meta_robots', 'canonical', 'nb_hreflang', 'problemes'])

for numero, url in enumerate(urls_du_sitemap(sitemap)):
    if numero >= LIMITE:
        break

    code, entetes, corps = lire(url)
    html = corps.decode('utf-8', 'replace')
    balises = Balises()
    balises.feed(html)
    x_robots = entetes.get('X-Robots-Tag', '') if entetes else ''
    problemes = []

    if code != 200:
        problemes.append(f'code {code}')

    if 'noindex' in (x_robots + balises.robots).lower():
        problemes.append('noindex')

    if balises.canonical and normaliser(balises.canonical) != normaliser(url):
        problemes.append('canonical to another URL')

    if balises.canonical and urlparse(balises.canonical).netloc != hote:
        problemes.append('canonical on another host')

    if any(urlparse(h).netloc != hote for h in balises.hreflang if h.startswith('http')):
        problemes.append('hreflang to another host (to check)')

    for interdit in hotes_interdits:
        if interdit in html:
            problemes.append(f'mentions {interdit}')

    sortie.writerow([url, code, x_robots, balises.robots, balises.canonical, len(balises.hreflang), ' ; '.join(problemes)])
```

Open `controle.csv` in a spreadsheet and filter the `problemes` column on non-empty cells. The script reads the initial HTML, not the JavaScript-rendered output: if your site injects the canonical on the client side, also check the rendered output (see [check title, description and canonical after rendering](https://checklist-seo-geo.com/en/javascript-html-rendering/check-title-description-canonical-after-rendering)). A “hreflang to another host” alert is normal if your languages are on separate domains. On a password-protected staging site, use Screaming Frog with authentication instead.

### Step 3 — Check canonicals across the whole site

The script only sees the URLs in the sitemap. For other pages (pagination, filters, unlisted product pages), crawl the site with Screaming Frog (free up to 500 URLs): `Canonicals` tab, `Non-Indexable Canonical`, `Canonicalised` and `Missing` filters. The underlying rules are in [check canonicals and absolute URLs](https://checklist-seo-geo.com/en/indexing-canonicalization/check-canonicals-absolute-urls) and [align canonicals, sitemap and internal links](https://checklist-seo-geo.com/en/indexing-canonicalization/align-canonicals-sitemap-internal-links).

### Step 4 — Check hreflang

In Screaming Frog, enable storing and crawling hreflang under `Configuration > Spider`, crawl, then open the `Hreflang` tab: use the `Missing Return Links` filter and the filters for non-`200` targets and non-canonical targets. If your hreflang annotations are in the sitemap, also crawl the sitemap in list mode. The rules on reciprocity and status codes are covered in detail in [check reciprocity](https://checklist-seo-geo.com/en/hreflang-regional-variants/check-reciprocity) and [align hreflang and canonical](https://checklist-seo-geo.com/en/hreflang-regional-variants/align-hreflang-canonical).

### Step 5 — Check the sitemaps

- The sitemap contains only URLs from the new site, returning `200`, indexable and canonical: the script's `problemes` column must be empty.
- The number of URLs is consistent with the crawl: a large gap points to forgotten pages or stray URLs.
- Each file respects the limit of 50,000 URLs and 50 MB uncompressed.
- The sitemap of old URLs, if there is one, is kept separate: see [submit new sitemaps](https://checklist-seo-geo.com/en/redesign-migration/submit-new-sitemaps).

### WordPress

Versions: WordPress 6.4 and later, Yoast SEO and Rank Math, November 2026.

Canonical, hreflang and sitemaps are built from `Settings > General`, “WordPress Address (URL)” and “Site Address (URL)” fields. After copying the staging site, replace every occurrence of the old address in the database, starting with a dry run:

```bash
wp search-replace 'https://staging.example.com' 'https://example.com' --all-tables --dry-run
wp search-replace 'https://staging.example.com' 'https://example.com' --all-tables
wp cache flush
```

The sitemap is at `/sitemap_index.xml` with Yoast SEO and Rank Math, and at `/wp-sitemap.xml` without a plugin. The `robots.txt` served by default is virtual; a physical `robots.txt` file at the root replaces it. Then clear the page cache and the CDN.

### Shopify

Versions: Shopify admin, all plans, November 2026.

Shopify generates the canonical (`canonical_url` variable in `layout/theme.liquid`), the `/sitemap.xml` sitemap and the `robots.txt` from the primary domain set in `Settings > Domains`. Check that the new domain is set as primary there and that the others redirect to it. If the theme contains a customized `templates/robots.txt.liquid` template, review it: a rule added during development stays there. With Shopify Markets, hreflang annotations are generated for each published market and language.

### Wix

Versions: Wix dashboard, Premium plans with a connected domain, November 2026.

Wix generates the canonical, sitemap and `robots.txt` for the connected domain. Check that the new domain is the primary domain, and review any custom canonical tags in the pages' SEO settings: a URL entered by hand is not updated automatically.

### Laravel

Versions: Laravel 11 to 13.

URLs generated during an HTTP request (`url()`, `route()`) use the request's host; those generated from the command line, such as a sitemap produced by a scheduled task, use `APP_URL`. A staging value left in the production `.env` therefore produces correct pages and a wrong sitemap. Check the value, clear the configuration cache and regenerate:

```bash
grep APP_URL .env
php artisan config:clear && php artisan config:cache
php artisan schedule:list
```

Behind a load balancer or a CDN, configure trusted proxies so that the `https` scheme and the host are correct in canonicals.

### Next.js

Versions: Next.js 15 and 16 (App Router).

Relative URLs in metadata are resolved with `metadataBase`: define it once in the root layout, from a production environment variable.

```ts
// app/layout.tsx
import type { Metadata } from 'next';

export const metadata: Metadata = {
  metadataBase: new URL(process.env.SITE_URL ?? 'https://example.com'),
  alternates: {
    canonical: '/',
    languages: {
      'fr-FR': '/fr',
      'en-GB': '/en',
    },
  },
};
```

In each page, redefine `alternates.canonical` with its own path. The `app/sitemap.ts` and `app/robots.ts` files must use the same `SITE_URL` variable; check its value in the host's production environment variables, then redeploy.

## Common mistakes

- **Checking only the staging site**: the production configuration (environment variables, CDN, cache) is different. Run the check again on the live site within the hour after the switchover.
- **Canonical pointing to a URL that redirects**: common when slugs changed after the tags were generated, or when the trailing slash differs.
- **Sitemap generated once before the switchover**: a static file keeps the staging URLs or the old URLs. Regenerate it in production.
- **`Disallow: /` left in `robots.txt`**: the whole site can no longer be crawled; see [remove indexing blocks on the live site](https://checklist-seo-geo.com/en/redesign-migration/remove-indexing-blocks-live-site).
- **Hreflang updated for only one language**: reciprocity is broken and Google ignores the annotations on the pages concerned.
- **Forgetting secondary outputs**: RSS feeds, structured data, Open Graph tags and `llms.txt` files also contain absolute URLs that need updating.

## Frequently asked questions

### Should old URLs stay in the sitemap after a redesign?

Not in the main sitemap, which should list only the new URLs returning 200. During a site move, however, Google advises also submitting a separate sitemap of the old URLs to speed up the discovery of the redirects. Search Console then reports URLs that redirect: that is expected. Remove this temporary sitemap once the new URLs are indexed.

### Can a canonical pointing to staging get the site deindexed?

Yes, it can cause the pages concerned to drop out of the index. The canonical tells Google which URL to index; if it points to a password-protected or blocked staging site, Google cannot index it and may also exclude the live page, or choose another canonical itself. Fix the tag, then request indexing of the main pages with the URL Inspection tool.

### How do you quickly check hreflang after a migration?

Crawl the new site with Screaming Frog with storing and crawling hreflang enabled, then look at the Hreflang tab: missing return links, targets that do not return 200 and non-canonical targets. If the annotations are in the sitemap, also crawl the sitemap in list mode. Each version must point to the new URLs of all the other languages, and to itself.

### Can the staging robots.txt end up in production?

Yes, it is one of the most common incidents. A staging site often has a robots.txt that blocks everything with Disallow: /, and a deployment that copies files as they are carries it into production. Google generally caches the file for up to 24 hours: fix it, then request a recrawl from the Search Console robots.txt report.

## Resources

- [Google Search Central: Site moves with URL changes](https://developers.google.com/search/docs/crawling-indexing/site-move-with-url-changes?hl=en)
- [Google Search Central: How to specify a canonical URL](https://developers.google.com/search/docs/crawling-indexing/consolidate-duplicate-urls?hl=en)
- [Google Search Central: Localized versions of your pages](https://developers.google.com/search/docs/specialty/international/localized-versions?hl=en)
- [Google: robots.txt specification](https://developers.google.com/crawling/docs/robots-txt/robots-txt-spec?hl=en)
- [Google Search Central: Build and submit a sitemap](https://developers.google.com/search/docs/crawling-indexing/sitemaps/build-sitemap?hl=en)
- [Search Console Help: robots.txt report](https://support.google.com/webmasters/answer/12818275?hl=en)
- [WP-CLI: search-replace command](https://developer.wordpress.org/cli/commands/search-replace/)
- [Next.js: generateMetadata and metadataBase](https://nextjs.org/docs/app/api-reference/functions/generate-metadata)

Next steps: [remove indexing blocks on the live site](https://checklist-seo-geo.com/en/redesign-migration/remove-indexing-blocks-live-site) and [submit new sitemaps](https://checklist-seo-geo.com/en/redesign-migration/submit-new-sitemaps).
