hreflang bad code

warning hreflang-bad-code hreflang and language versions

An alternate with an empty or malformed href is a broken link inside the signal that is supposed to hold the language versions together. So is an href in a form the build does not serve: `/de/a` for `de/a/index.html` is a redirect, `/de/a/` for `de/a.html` is a 404 on GitHub Pages, S3 and nginx, and `/de/a/index.html` next to a canonical `/de/a/` is a copy. Hosting settings that serve the form (cleanUrls, trailingSlash, redirect rules) keep it quiet. The code itself is checked the way Google reads it: a language from ISO 639-1, an optional script from ISO 15924 (zh-Hans, sr-Latn) and an optional country from ISO 3166-1 alpha-2. Google says other codes are not supported, so es-419 (a UN region) is reported with the countries to list instead, en-UK and en-EU with what UK and EU are not, country codes in the language slot (jp, cn, dk, gr) with the language meant, withdrawn codes (iw, in) with their successors, and three-letter codes (fil, yue) with the ISO 639-1 code where one exists. When zh-Hans and zh-CN (or zh-Hant and zh-TW) lead to different pages, a note says they are the same readers.

What indexgap reports

The finding reads:

warning  hreflang-bad-code  the “…” alternate has an empty href

How to fix it

Fix the language code: usually a country has been written where a language belongs. Write the alternate address exactly as the version's canonical: /de/a/ for de/a/index.html, /de/a.html for de/a.html.

How it behaves at scale

Collapsed when it fires template-wide. If it appears on 90% or more of the pages — or of one language version — of a site with at least 20 pages, it is a property of the template and is reported once, with the count, instead of once per page.

Finding it

pipx install indexgap
cd your-project
indexgap init
indexgap check

Then indexgap brief turns every finding on this page into a work order in indexgap-briefs/, with the thresholds the result has to satisfy and the command to check it.

Related checks in hreflang and language versions

All checks · hreflang and language versions