Prompt
I’m building a workflow for hreflang validation across country sites, how do I do it?
Latest observation
Here’s a practical way to build a hreflang validation workflow for country/language sites.
1) Define the rules you want to validate
At minimum, your checker should confirm:
- Every indexable localized page has hreflang tags
- Each hreflang points to the correct URL
- Reciprocal links exist
If page A references page B, page B must reference page A. - Self-referencing hreflang exists
- Language/region codes are valid
e.g.en,en-GB,fr-FR,es-MX - Each cluster includes an x-default if required
- All alternates are canonical/indexable
- No broken URLs, redirects, 404s, or blocked pages
- Only one hreflang set per page
- Consistent implementation method
HTML tags, HTTP headers, or XML sitemap — ideally one primary method
2) Decide where hreflang lives
Pick one source of truth:
Option A: HTML <link rel="alternate" hreflang="...">
Best for:
- Smaller to medium sites
- Easy page-level validation
Option B: XML sitemap hreflang annotations
Best for:
- Large sites
- Cleaner templates
- Centralized generation
Option C: HTTP headers
Best for:
- PDFs and non-HTML assets
Many teams use HTML + sitemap together, but if you do, make sure they match exactly.
3) Build the workflow in stages
Stage 1: Crawl
Use a crawler to collect:
- All indexable URLs
- Canonicals
- Hreflang annotations
- Status codes
- Redirect chains
- Robots/noindex flags
Tools you can use:
- Screaming Frog
- Sitebulb
- Oncrawl
- Custom crawler using Python + requests/BeautifulSoup or Playwright
- Google Search Console exports as a supplement
Stage 2: Normalize
Normalize all URLs before checking:
- Remove trailing slash inconsistencies
- Resolve relative URLs
- Force consistent protocol/host rules
- Strip fragments
- Handle parameters according to policy
Stage 3: Group into hreflang clusters
Treat one set of localized equivalents as a cluster.
Example:
example.com/en-us/pageexample.com/en-gb/pageexample.com/fr-fr/page
Each cluster should contain:
- all localized variants
- self-reference
- optional x-default
Stage 4: Validate rules
For each page:
- Does it have hreflang?
- Are codes valid?
- Does self-reference exist?
- Do all linked alternates return 200?
- Are alternates canonical?
- Are reciprocal links present?
- Is x-default present where needed?
- Are there duplicates/conflicts?
Stage 5: Report errors by severity
Use a severity model:
- Critical: missing reciprocity, broken URLs, invalid codes, redirects in hreflang, no self-reference
- High: canonical mismatch, missing one locale in a cluster
- Medium: inconsistent x-default, partial coverage
- Low: formatting issues, ordering inconsistencies
Stage 6: Alert and fix
Push issues to:
- Jira/Asana tickets
- Slack alerts
- Email digests
- CI/CD checks for releases
4) Recommended validation logic
A good workflow validates at both page level and cluster level.
Page-level checks
For each page:
- Parse hreflang alternates
- Ensure one tag per locale
- Ensure URLs are absolute and indexable
- Ensure the page’s own locale points to itself
- Ensure canonical matches intended version
Cluster-level checks
Across all variants:
- All pages in the cluster list the same set of alternates
- Every page references every other page in the cluster
- No extra stray URL appears in only one page’s hreflang set
This is important because hreflang failures often happen when one page is updated and others aren’t.
5) Example of a valid hreflang set
<link rel="alternate" hreflang="en-us" href="https://example.com/us/page" />
<link rel="alternate" hreflang="en-gb" href="https://example.com/uk/page" />
<link rel="alternate" hreflang="fr-fr" href="https://example.com/fr/page" />
<link rel="alternate" hreflang="x-default" href="https://example.com/page" />
Each localized version should include the same set, including itself.
6) Implementation approach in code
If you’re building this yourself, the architecture can be:
Input
- Sitemap(s)
- Crawl results
- CMS locale mapping
- Canonical map
Processing
- Fetch HTML or sitemap annotations
- Extract hreflang data
- Validate URLs with HEAD/GET
- Group by canonical content ID or localization key
- Compare sets for reciprocity and completeness
- Emit report
Output
- CSV/JSON report
- Dashboard
- Slack alerts
- Pull request comments if used in CI
7) Useful checks to automate
Automate these specific conditions:
- Status code check: alternate URL must return 200
- Redirect check: avoid hreflang URLs that redirect
- Canonical check: alternate must canonicalize to itself
- Robots check: page must not be noindex or blocked if intended for hreflang
- Language code check: must match ISO 639-1 + optional region ISO 3166-1 alpha-2
- Reciprocity check: A → B implies B → A
- Coverage check: all localized variants included
- Duplicate check: no repeated hreflang values on the same page
8) Good operational process
A simple team workflow:
- Developer pushes locale changes
- CI runs hreflang validation
- Failures block deploy or create warning
- SEO reviews report
- Content/engineering fixes mappings
- Post-deploy crawl verifies live state
9) Common mistakes to catch
Make sure your workflow flags:
- Missing self-references
- Mixed uppercase/lowercase inconsistencies in codes
- Using country code without language when not appropriate
- Pointing to redirected URLs
- Incomplete alternate sets
- Mismatched canonical and hreflang targets
- hreflang on non-indexable pages
- Inconsistent trailing slashes/parameters
- x-default pointing to a localized page instead of a neutral selector page
10) Best-practice setup
If you want a robust setup, I’d recommend:
- Use a central locale mapping table
- Generate hreflang from the CMS or localization config
- Validate in CI/CD
- Crawl live pages nightly
- Store results historically
- Trigger alerts on regressions
- Maintain a single “content ID” linking equivalent pages
11) A simple checklist
Your workflow is good if it answers:
- Which pages should have hreflang?
- What is the complete alternate set for each page?
- Are all alternates live and canonical?
- Is reciprocity complete?
- Are codes valid?
- Is x-default handled correctly?
- Are there regressions over time?
If you want, I can also give you:
- a sample validation schema in JSON,
- a Python script to crawl and validate hreflang,
- or a workflow diagram for SEO + engineering teams.