Check 23.11 · Hreflang and regional variants

Exclude redirects and nonexistent pages

Generate hreflang that lists only published translations, at their final URL: rules for WordPress, Shopify, Laravel, Next.js and sitemaps.

Priority
Critical
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 hreflang group must only list pages that exist and are served at the announced address. The task is to configure the source of the annotations (CMS, template, sitemap generator, server configuration) so that it excludes three cases on its own: missing or deleted translations, unpublished translations, and old URLs that now redirect. Where check that targets return HTTP 200 (opens in a new tab) detects the problem after the fact, this task stops it from happening again. Once done, every new page, deletion or slug change produces correct annotations with no manual work.

Why it matters

Google asks that each version of a page list all the others and itself, and that the links be reciprocal: otherwise the annotations may be ignored. A target that does not exist (404, 410) cannot return a link. A redirected target forces Google to connect the old URL with the new one; Google's John Mueller said in 2025 that annotations pointing to 301 redirects were “probably” acceptable, but advised automating the annotations so they point to the final URLs.

Incorrect annotations almost always have the same origin: a template that outputs one line for each active language on the site, instead of one line for each actual translation of the page. The site has five languages, the page exists in only three, and the template announces five, including two URLs guessed by swapping the language prefix. The problem grows with the catalog: every untranslated product, every withdrawn article, every changed translated slug adds broken annotations.

This task also touches on the missing translation case: what should a visitor who switches language on an untranslated page see? That interface decision belongs to plan for missing translations (opens in a new tab); here, you only make sure that search engines receive no annotation pointing to a page that does not exist.

What it improves

  • hreflang groups taken into account No more pairs that cannot be verified.
  • Maintenance The annotations automatically follow publications, deletions and slug changes.
  • Crawling Fewer requests wasted on 404s and redirects, which is noticeable on large catalogs.
  • Experience A language switcher built on the same data no longer leads to empty pages.
  • Generative engines No documented direct effect.
  • Rankings No direct effect.

How to check

1. Compare annotations with actual translations. Pick a page you know is not translated into one language, and read its annotations:

curl -s https://example.com/fr/guide-installation/ | grep -o -i '<link[^>]*hreflang[^>]*>'

Compliant: the missing language does not appear. Non-compliant: an hreflang="de" line pointing to a guessed URL that returns 404 or redirects.

2. After a slug change. Change a translated slug on staging, then check that the other versions announce the new URL, not the old one:

curl -s https://staging.example.com/en/pricing/ | grep -o -i 'hreflang="fr[^"]*"[^>]*href="[^"]*"'

3. Across the whole site. After a Screaming Frog crawl with hreflang crawling enabled, the “Non-200 Hreflang URLs” filter in the Hreflang tab and the Reports > Hreflang report show which source pages list targets that return errors or redirect. Sort by response code: 404s reveal a template that guesses URLs, 301s a slug change or migration that was not carried over.

4. In the sitemap. If the annotations are in it, apply the same test to the xhtml:link links and compare the list of <loc> entries with the list of published pages.

How to implement

Before you start

The rule the code must enforce, whatever the environment:

A version is listed in the group if… Otherwise
the translation exists for this specific page it is left out of the group
it is published (not a draft, not scheduled) it is left out of the group
it is indexable (see check that targets are indexable (opens in a new tab)) it is left out of the group
its URL is built from its own slug, in its canonical form the URL is fixed at the source

Three principles complete this rule:

  • Never guess a URL by replacing /fr/ with /de/: translated slugs differ, and the page may not exist.
  • Read URLs from the content, not from the redirects: after a slug change, the CMS knows the new URL; the redirect only serves visitors and external links.
  • A single source for the HTML, the sitemap and the headers: the same function or query feeds all three.

During a migration, update the annotations at the same time as the redirect plan, not afterwards (see check canonicals, hreflang, sitemaps and robots.txt (opens in a new tab)).

WordPress

Versions WordPress 6.8 and later; WPML 4 and 5, Polylang 3, TranslatePress 3, Weglot 6.

  • WPML and Polylang explicitly link each piece of content to its translations: they only announce existing translations, based on their permalinks. Points to watch: content in fallback mode (WPML can display the default-language content when the translation is missing, in WPML > Settings, Post Types Translation, in WPML 4 as in WPML 5) and translation links broken after an import. For content in fallback mode, check the source code: a page served in the original language under a translation URL must not be announced as a translation.
  • TranslatePress and Weglot translate pages on the fly: every page exists in every active language, even if its text has not been translated. For pages you will not translate, use the plugin's path exclusion (TranslatePress Advanced tab, URL exclusions in the Weglot dashboard) so that they are neither served nor announced in the other languages.
  • Deletions: move the translation itself to the trash, not just the original, and check that the plugin does not keep a link to deleted content.

After every slug change or deletion, clear the page cache and regenerate the SEO plugin's sitemaps.

Shopify

Versions Shopify with Shopify Markets, all plans, November 2026.

The automatic annotations cover every published language of every market, for all pages. An untranslated resource is displayed in the store's default language under the published language's URL: it therefore exists, but it is not a real translation. Two solutions:

  • Only publish a language (Settings > Languages, then activate it per market) once the catalog is translated, with the Translate & Adapt app or a translation app;
  • Manage the annotations yourself after turning off the automatic hreflang tags option in Online Store > Preferences, in the social sharing and SEO section, building them from the localization Liquid object, with no hard-coded domain or handle, as Shopify's documentation requires.

When you change a handle, Shopify offers to create a redirect: keep it for visitors; the automatic annotations use the new handle.

Laravel

Versions Laravel 11 to 13.

Build the annotations from the resource's actually published translations, never from the site's list of languages:

// app/Models/Page.php
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Collection;

public function translations(): HasMany
{
    return $this->hasMany(PageTranslation::class, 'group_id', 'group_id');
}

/** @return Collection<string, string> */
public function hreflangAlternates(): Collection
{
    return $this->translations()
        ->whereNotNull('published_at')
        ->where('published_at', '<=', now())
        ->where('is_indexable', true)
        ->get()
        ->mapWithKeys(fn (PageTranslation $translation): array => [
            config("app.supported_locales.{$translation->locale}.hreflang") => route('pages.show', [
                'locale' => config("app.supported_locales.{$translation->locale}.prefix"),
                'slug' => $translation->slug,
            ]),
        ]);
}

The Blade component and the sitemap generator both call hreflangAlternates(). When a slug changes, store the old one in a redirects table for visitors, but never use it to produce an annotation.

Next.js

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

Only fill alternates.languages with the locales where the content exists, by reading your CMS or your files:

// app/[locale]/blog/[slug]/page.tsx
import type { Metadata } from 'next';
import { notFound } from 'next/navigation';
import { getArticle } from '@/lib/content';

type Props = { params: Promise<{ locale: string; slug: string }> };

export async function generateMetadata({ params }: Props): Promise<Metadata> {
  const { locale, slug } = await params;
  const article = await getArticle(locale, slug);

  if (!article) {
    notFound();
  }

  const languages = Object.fromEntries(
    article.translations
      .filter((translation) => translation.published)
      .map((translation) => [translation.hreflang, `/${translation.locale}/blog/${translation.slug}`]),
  );

  return {
    metadataBase: new URL('https://example.com'),
    alternates: {
      canonical: `/${locale}/blog/${slug}`,
      languages,
    },
  };
}

article.translations must include the current version, for the self-reference. With static generation, regenerate the pages in the other languages when a translation is added or removed (revalidatePath or a new build): otherwise they keep outdated annotations.

XML sitemaps

If a script or plugin produces the annotations in the sitemap, apply the same rule there: one xhtml:link entry per published, indexable translation, with its final URL. Exclude URLs that redirect or return 404 from the sitemap (see exclude unpublished or non-indexable translations (opens in a new tab)). Then resubmit the file in Search Console's Sitemaps report.

Apache

Versions Apache 2.4.

Hand-written Link headers for PDFs do not follow deletions. List them and test each target:

sudo grep -rhoE '<https?://[^>]+>' /etc/apache2/ /var/www/*/.htaccess 2>/dev/null | tr -d '<>' | sort -u \
  | while read -r url; do echo "$(curl -s -o /dev/null -w '%{http_code}' "$url") $url"; done

Remove from the Header set Link directive any version whose file has disappeared, on every file in the group, then reload Apache.

Nginx

Versions Nginx 1.24 and later.

Run the same check in /etc/nginx/ for add_header Link directives. If many files are annotated, generate these blocks from a list maintained alongside the files, rather than by hand.

Common mistakes

  • One annotation per site language instead of one per translation of the page.
  • Guessing the translated URL by changing the language prefix.
  • Using the old URL and relying on the redirect after a slug change.
  • Announcing a draft or a scheduled page, which returns 404 to the public.
  • Fixing the HTML and forgetting the sitemap, or the other way round: two sources, two truths.
  • Leaving static pages in the cache with old annotations after a translation is deleted.
  • Announcing a fallback page displayed in the original language as a translation.

Frequently asked questions

Do all pages need an hreflang annotation for every language on the site?

No. A page only announces its own actual translations, published and indexable. If an article exists only in French and English on a site in five languages, its hreflang group contains two versions, plus x-default if needed. Announcing all five languages produces annotations pointing to nonexistent or redirected URLs, which Google cannot confirm through a return link.

What should you do with hreflang annotations after a slug change?

Update every version in the group so that they announce the new URL, and keep the redirect from the old URL for visitors and external links. A CMS or template that builds the annotations from the current slugs does this automatically. An annotation pointing to the old URL goes through a redirect, which Google advises avoiding by pointing directly to the final URL.

Should a page shown in the original language for lack of a translation be announced?

No. A page served under a translation URL but with the original-language text is not a translation: announcing it in hreflang amounts to offering German speakers a French text. Remove it from the annotations, and preferably do not serve it at all under the translation URL, by excluding the path in the multilingual plugin or by publishing the language only once the content is translated.

How do you keep hreflang annotations from degrading over time?

Generate them automatically from the CMS data, with a single function for the HTML, the sitemap and the headers, and list only published translations. Add an automated test that checks that each target returns 200, and a scheduled crawl that monitors targets returning errors. Hand-written annotations always end up pointing to deleted or renamed pages.

Updated on

Topic checklist (PDF)

And now?

In the “Hreflang and regional variants” topic

  1. Implement hreflang for equivalent pages
  2. Check reciprocity
  3. Include the self-referencing annotation
  4. Use absolute URLs
  5. Validate ISO 639-1 language codes
  6. Validate ISO 3166-1 Alpha-2 country codes
  7. Use en-GB rather than en-UK
  8. Use x-default if relevant
  9. Check that targets return HTTP 200
  10. Check that targets are indexable
  11. Exclude redirects and nonexistent pages
  12. Align hreflang and canonical
  13. Automate annotations through the CMS
  14. Update annotations when a translation is removed
  15. Use HTTP headers for PDFs if needed
  16. Check consistency across HTML, HTTP header and sitemap methods if combined
  17. Test same-language variants for different countries