hreflang set does not include the page itself
What Is This Issue
Hreflang Self-Referencing Tag (Each Page References Itself)
This issue checks whether every page that participates in an hreflang cluster includes a self-referencing hreflang tag pointing to its own URL. Google requires this for the hreflang set to be considered complete and valid.
What This Issue Checks
The audit verifies that each page in a hreflang cluster includes a hreflang tag whose href attribute points back to the page itself. This signals to Google that the page is aware of its own place in the internationalized cluster.
What is Considered a Passing Implementation
Your website passes this check when:
- Every language variant page includes a self-referencing hreflang tag
- The self-referencing href points to the page’s own canonical URL
- The self-referencing href is a fully qualified absolute URL (including scheme and host)
- The URL scheme of the self-referencing href matches the crawled page URL scheme (both https or both http)
- The self-referencing tag uses a valid ISO 639-1 language code
Real-World Example
Passing Implementation:
<!-- On the English page: https://example.com/en/ -->
<link rel="alternate" hreflang="en" href="https://example.com/en/" />
<link rel="alternate" hreflang="fr" href="https://example.com/fr/" />
<link rel="alternate" hreflang="es" href="https://example.com/es/" />Failing Implementation:
<!-- On the English page: https://example.com/en/ -->
<!-- Missing self-referencing tag for en -->
<link rel="alternate" hreflang="fr" href="https://example.com/fr/" />
<link rel="alternate" hreflang="es" href="https://example.com/es/" />Why Is This Important
Impact on SEO
Crawlability
Self-referencing hreflang tags help search engines understand the structure of your hreflang clusters. Without them, search engines may not properly crawl and understand the relationship between language variants.
Indexability
Google’s hreflang specification requires that every page in a hreflang cluster include a self-referencing hreflang tag. Without it, Google may treat the hreflang cluster as incomplete and may not index the page as part of the international cluster.
Rankings
When pages properly self-reference in hreflang clusters, search engines can correctly serve the appropriate language version to users in different regions. This improves international ranking signals and ensures users see the correct language in search results.
User Experience
Proper hreflang self-referencing ensures that users are directed to the correct language version of your content. Without it, users may land on incorrect language pages, leading to poor user experience and higher bounce rates.
Duplicate Content
Self-referencing hreflang tags help search engines understand that pages in different languages are alternate versions of each other, not duplicate content. This prevents duplicate content issues across language variants.
AI Search / AEO
As AI-powered search becomes more prevalent, properly structured self-referencing hreflang tags help AI understand your content’s language targeting within the hreflang cluster, ensuring accurate representation in AI-generated answers across different languages.
How Resolving This Issue Improves SEO Health Score
Fixing hreflang self-referencing issues improves your overall SEO health score by:
- Ensuring complete hreflang cluster recognition by search engines
- Preventing hreflang clusters from being ignored due to missing self-references
- Improving international SEO signals for all language variants
- Reducing incorrect language version serving
- Strengthening the overall international SEO structure of your website
How XeoPix Detects This
XeoPix checks whether every page that participates in an hreflang cluster includes a self-referencing hreflang tag pointing to its own URL, as required by Google.
Detection Process
XeoPix follows these logical steps to identify missing self-referencing hreflang tags:
1. Fetch the Page and Resolve URL
XeoPix issues an HTTP GET request to the target URL and captures the final resolved URL after any redirects. This becomes the canonical page URL for comparison.
2. Extract All Hreflang Tags
XeoPix parses the <head> section of the raw HTML to find all <link rel="alternate" hreflang="..."> tags and extracts their href attributes.
3. Normalize URLs for Comparison
XeoPix normalizes both the page’s canonical URL and the hreflang href values:
- Adds trailing slash if missing (for consistency)
- Lowercases scheme and host
- Resolves relative URLs to absolute URLs
4. Check for Self-Reference
XeoPix compares each hreflang href value against the page’s own canonical URL to determine if any hreflang tag points to the page itself.
5. Validate Self-Referencing Tag
If a self-referencing tag is found, XeoPix validates:
- Whether the href is a fully qualified absolute URL (includes scheme and host)
- Whether the URL scheme matches the crawled page URL scheme (https vs http)
- Whether the language code is a valid ISO 639-1 value
6. Count Hreflang Cluster Size
XeoPix counts the total number of hreflang alternate tags found on the page to check if there’s only one tag (which would indicate an incomplete cluster).
When the Issue is Flagged
The issue is flagged when any of these conditions are met:
- Missing self-referencing tag: No hreflang tag’s href matches the page’s own canonical URL
- Only one hreflang tag: Only one hreflang tag exists on the page (needs at least self-reference + one alternate)
- Self-referencing href not absolute: The self-referencing hreflang href is not a fully qualified absolute URL
- Scheme mismatch: The self-referencing href uses a different scheme (http/https) than the crawled page
When the Issue Passes
The issue passes when:
- A self-referencing hreflang tag is present on the page
- The self-referencing href points to the page’s canonical URL
- The self-referencing href is a fully qualified absolute URL
- The URL scheme matches the crawled page scheme
- The page has more than one hreflang tag (indicating a complete cluster)
How To Fix
Practical Recommendations
1. Add Self-Referencing Hreflang Tag to Every Language Page
Every page that participates in a hreflang cluster must include a hreflang tag that points to itself.
Implementation:
<!-- On the English page (https://example.com/en/) -->
<link rel="alternate" hreflang="en" href="https://example.com/en/" />
<!-- On the French page (https://example.com/fr/) -->
<link rel="alternate" hreflang="fr" href="https://example.com/fr/" />2. Use the Exact Canonical URL
The self-referencing hreflang tag must point to the page’s exact canonical URL:
- Include the correct scheme (
https://nothttp://) - Include the full domain
- Match the canonical URL exactly (trailing slashes, case sensitivity)
Correct:
<link rel="alternate" hreflang="en" href="https://example.com/en/" />Incorrect:
<link rel="alternate" hreflang="en" href="/en/" />
<link rel="alternate" hreflang="en" href="http://example.com/en/" />
<link rel="alternate" hreflang="en" href="https://example.com/en" />
<!-- Missing trailing slash if canonical uses trailing slash -->3. Include All Alternate Tags on Every Page
Don’t add hreflang tags only on the homepage. Every page in the cluster must include:
- Its own self-referencing tag
- All alternate language tags
Example for all pages:
<!-- On ALL pages (en, fr, es) -->
<link rel="alternate" hreflang="en" href="https://example.com/en/" />
<link rel="alternate" hreflang="fr" href="https://example.com/fr/" />
<link rel="alternate" hreflang="es" href="https://example.com/es/" />4. Ensure URL Scheme Matches
The URL scheme in the self-referencing hreflang tag should match the scheme of the page being crawled:
- If the page is served over HTTPS, the self-referencing href should use
https:// - If the page is served over HTTP, the self-referencing href should use
http://
5. Use Valid Language Codes
Ensure the self-referencing hreflang tag uses a valid language code:
- ISO 639-1 language codes (e.g.,
en,fr,es) - ISO 639-1 + ISO 3166-1 for regional variants (e.g.,
en-US,fr-CA)
Priority Order
- First: Add missing self-referencing hreflang tags to all language variant pages
- Second: Ensure all self-referencing hrefs use absolute URLs with correct scheme
- Third: Verify self-referencing hrefs match the page’s canonical URL exactly
- Fourth: Add complete hreflang clusters (all alternates) to every page
- Fifth: Validate language codes in self-referencing tags
What We Store
Storage Level
Page Level
Database Table / Prisma Model
PageInternationalSeo
Stored Fields
| Field | Type | Description |
|---|---|---|
| hreflangTags | Json? | The hreflang tags found on the page |
| invalidLangCodes | String[] | Invalid language codes detected |
Detection Dependencies
- HTML Document
- HTTP Response Headers
Examples
Example 1: Missing Self-Referencing Hreflang Tag
Scenario
A website has English and French pages with hreflang tags, but the English page doesn’t reference itself.
Problematic State (Fails)
<!-- On page: https://example.com/en/ -->
<!-- Missing self-referencing tag for en -->
<link rel="alternate" hreflang="fr" href="https://example.com/fr/" />Result: Google may treat the hreflang cluster as incomplete and ignore the hreflang declarations.
Corrected State (Passes)
<!-- On page: https://example.com/en/ -->
<link rel="alternate" hreflang="en" href="https://example.com/en/" />
<link rel="alternate" hreflang="fr" href="https://example.com/fr/" />Result: Google recognizes the complete hreflang cluster and properly associates the language variants.
Example 2: Self-Referencing Hreflang Uses Relative URL
Scenario
Self-referencing tag exists but uses a relative URL instead of absolute URL.
Problematic State (Fails)
<!-- On page: https://example.com/en/ -->
<link rel="alternate" hreflang="en" href="/en/" />
<!-- Relative URL - not valid for hreflang -->
<link rel="alternate" hreflang="fr" href="https://example.com/fr/" />Result: Google requires all hreflang href values to be absolute URLs. The relative URL may be ignored.
Corrected State (Passes)
<!-- On page: https://example.com/en/ -->
<link rel="alternate" hreflang="en" href="https://example.com/en/" />
<link rel="alternate" hreflang="fr" href="https://example.com/fr/" />Result: All hreflang hrefs are valid absolute URLs that Google can process.
Example 3: Self-Referencing Hreflang Scheme Mismatch
Scenario
Page is served over HTTPS but self-referencing hreflang uses HTTP.
Problematic State (Fails)
<!-- Page URL: https://example.com/en/ -->
<link rel="alternate" hreflang="en" href="http://example.com/en/" />
<!-- Scheme mismatch: page is https, but hreflang uses http -->
<link rel="alternate" hreflang="fr" href="https://example.com/fr/" />Result: The hreflang cluster may be treated as mismatched due to inconsistent URL schemes.
Corrected State (Passes)
<!-- Page URL: https://example.com/en/ -->
<link rel="alternate" hreflang="en" href="https://example.com/en/" />
<link rel="alternate" hreflang="fr" href="https://example.com/fr/" />Result: All hreflang URLs use consistent HTTPS scheme, ensuring proper cluster recognition.
Unit Test
Test File
__tests__/seo-audit-checks/internationalSeo/issue-168-hreflang-self-referencing.test.js
Purpose
This unit test validates that the HREFLANG_SELF_REFERENCING issue is correctly detected when a page that participates in an hreflang cluster does not include a self-referencing hreflang tag pointing to its own URL.
Tested Function
runInternationalSeo(ctx) from toggleGroups/internationalSeo.js
Issue Information
- Issue Number: 168
- Issue Code:
hreflang_self_referencing - Toggle Group: internationalSeo
Test Scenarios
Positive Test Cases
- Should not detect HREFLANG_SELF_REFERENCING when a self-referencing hreflang tag exists (page URL matches one of the hreflang hrefs)
- Should not detect issue when the page has no hreflang tags at all
- Should not detect issue when URL normalization handles trailing slash differences (e.g.,
page/matchespage)
Negative Test Cases
- Should detect HREFLANG_SELF_REFERENCING when no hreflang tag points to the current page’s URL
- Should detect HREFLANG_SELF_REFERENCING with multiple hreflang tags when none are self-referencing
Edge Cases
- No hreflang tags: Empty HTML — should not detect the issue
- URL normalization (trailing slash): Page URL has a trailing slash (
/page/) while hreflang href does not (/page) — should handle URL normalization and not detect the issue - Multiple language tags: Four language tags without self-reference — should still detect the issue
Expected Outcome
Pass
The issue should be reported when the page has hreflang tags but none of them reference the page’s own URL.
Fail
The issue should not be reported when:
- A self-referencing hreflang tag exists
- No hreflang tags are present on the page
- URL normalization resolves the self-reference despite trailing slash differences
Validation
The unit test verifies:
- Correct detection of missing self-referencing hreflang tags
- No false positives when self-reference is present
- URL normalization (trailing slash) handling
- Correct issue code assignment
- Metadata (details) is included when the issue is detected
Related Production Files
toggleGroups/internationalSeo.js— containsrunInternationalSeo()issueCodes.js— definesHREFLANG_SELF_REFERENCINGissue code constant
Coverage Summary
- Covers presence and absence of self-referencing hreflang tags
- Includes URL normalization edge case (trailing slash)
- Covers no-hreflang scenario
- Validates metadata presence on detection
- Handles multiple hreflang tags
References
- Localized Versions - All Pages in Cluster — Google Search Central
- Managing Multi-Regional Sites — Google Search Central
- HTML Alternate Link Relations — MDN Web Docs