# Implement hreflang for equivalent pages

- Check 23.01 · Hreflang and regional variants · Critical
- Source: https://checklist-seo-geo.com/en/hreflang-regional-variants/implement-hreflang-equivalent-pages
- Link each page to its translations and regional variants with hreflang (HTML, HTTP header or sitemap) on WordPress, Shopify, Drupal, Laravel or Next.js.
- Updated on 2026-11-25
- Licence: CC BY 4.0. Credit “Checklist SEO & GEO” with a link to https://checklist-seo-geo.com/en/hreflang-regional-variants/implement-hreflang-equivalent-pages.
- Plugin checklist-seo-geo: 1.3.1 · https://github.com/maximegaul/checklist-seo-geo

## In short

`hreflang` annotations declare that a page exists in several languages or for several countries, and give the address of each version. Google uses them to show, in its results, the version that matches the searcher's language and country. Once the task is done, every translated page lists all its versions, itself included, with full URLs and valid codes, through a single method: tags in the `<head>`, an HTTP `Link` header or an XML sitemap.

## Why it matters

Without annotations, Google has to guess that `/fr/tarifs/` and `/en/pricing/` are the same page. It may then show the English version to a French-speaking searcher, or treat two very similar variants (`fr-FR` and `fr-CH`) as duplicates and show only one of them.

With `hreflang`, you build groups: each page in the group points to the others and to itself. Google applies strict rules, documented in its guide to localized versions:

- **Reciprocal links**: if two pages do not point to each other, the annotations are ignored. This is what stops a third-party site from declaring itself a translation of your pages.
- **Full URLs** with the protocol: `https://example.com/foo`, never `/foo`.
- **Standard codes**: language in ISO 639-1 (ISO, the International Organization for Standardization), optional region in ISO 3166-1 Alpha-2.

Google states that it does not use `hreflang` or the `lang` attribute to determine the language of a page: it detects it itself. `hreflang` links versions together; it does not describe the language.

Bing relies less on these annotations: in 2020, Fabrice Canel of the Bing team described `hreflang` as a much weaker signal than the `content-language` tag for that search engine. No generative engine (ChatGPT, Perplexity, Claude) documents any use of `hreflang`.

## What it improves

- **The right version in Google results**: the Swiss searcher sees the `fr-CH` URL, the Canadian searcher the `en-CA` URL.
- **Similar regional variants**: near-identical pages in the same language are recognized as variants; see [handle near-identical regional variants](https://checklist-seo-geo.com/en/multilingual-indexing-sitemaps/handle-near-identical-regional-variants).
- **Click-through rate and conversion**: fewer visitors land on a language they cannot read, with a currency or delivery terms that do not apply to them.
- **AI answers**: at best an indirect effect. AI Overviews rely on Google's index, which then knows the right version; nothing guarantees that a specific version will be cited.
- **Rankings**: no direct gain. `hreflang` routes searchers between your versions; it does not make them rank better.

## How to check

Read a page's annotations in the HTML returned by the server:

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

Correct result:

```txt
<link rel="alternate" hreflang="fr" href="https://example.com/fr/tarifs/">
<link rel="alternate" hreflang="en" href="https://example.com/en/pricing/">
<link rel="alternate" hreflang="de" href="https://example.com/de/preise/">
<link rel="alternate" hreflang="x-default" href="https://example.com/en/pricing/">
```

Repeat the test on `/en/pricing/` and `/de/preise/`: the list must be identical. If nothing comes out, look for the other two methods:

```bash
curl -sI https://example.com/fr/guide.pdf | grep -i '^link:'
curl -s https://example.com/sitemap.xml | grep -c 'xhtml:link'
```

Tools:

- **Merkle's hreflang tester**: checks a URL, its codes and the return links.
- **Screaming Frog**: enable "Store Hreflang" and "Crawl Hreflang" in `Configuration > Spider > Crawl`, then read the Hreflang tab, with the filters "Missing Return Links", "Incorrect Language & Region Codes", "Missing Self Reference" and "Non-200 Hreflang URLs".
- **Search Console**: the "International Targeting" report, which listed `hreflang` errors, was retired in 2022. [URL Inspection](https://search.google.com/search-console/inspect), with its crawled HTML view, remains useful if the tags are added by JavaScript.

## How to implement

### Before you start

**1. Draw up the table of groups.** One row per piece of content, one column per version. Only genuinely equivalent pages belong in the same group: a translation of the page, or the same page adapted for another country. Never the homepage of a language in place of a missing page.

| Group | fr | en | de | x-default |
|---|---|---|---|---|
| Pricing | `https://example.com/fr/tarifs/` | `https://example.com/en/pricing/` | `https://example.com/de/preise/` | `en` version |
| Contact | `https://example.com/fr/contact/` | `https://example.com/en/contact/` | `https://example.com/de/kontakt/` | `en` version |
| Guide | `https://example.com/fr/guide/` | missing | `https://example.com/de/leitfaden/` | none |

Each URL must return 200, be indexable and carry a canonical pointing to itself: see [use a self-referencing canonical for each actual translation](https://checklist-seo-geo.com/en/multilingual-indexing-sitemaps/use-self-referencing-canonical-each-actual-translation).

**2. Choose a single method.** Google treats them all the same way; combining several adds nothing and multiplies the risk of inconsistency.

| Method | When to choose it |
|---|---|
| `<link>` tags in the `<head>` | General case, HTML templates generated by the CMS or framework |
| HTTP `Link` header | Non-HTML files (PDF) |
| XML sitemap | Many languages, templates that are hard to change, centralized generation |

**3. Follow the format.** In the `<head>` of each of the three pages in the Pricing group:

```html
<link rel="alternate" hreflang="fr" href="https://example.com/fr/tarifs/">
<link rel="alternate" hreflang="en" href="https://example.com/en/pricing/">
<link rel="alternate" hreflang="de" href="https://example.com/de/preise/">
<link rel="alternate" hreflang="x-default" href="https://example.com/en/pricing/">
```

The sitemap equivalent, with the `xhtml` namespace declared and one `<url>` entry per version:

```xml
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
        xmlns:xhtml="http://www.w3.org/1999/xhtml">
  <url>
    <loc>https://example.com/fr/tarifs/</loc>
    <xhtml:link rel="alternate" hreflang="fr" href="https://example.com/fr/tarifs/"/>
    <xhtml:link rel="alternate" hreflang="en" href="https://example.com/en/pricing/"/>
    <xhtml:link rel="alternate" hreflang="de" href="https://example.com/de/preise/"/>
  </url>
  <url>
    <loc>https://example.com/en/pricing/</loc>
    <xhtml:link rel="alternate" hreflang="fr" href="https://example.com/fr/tarifs/"/>
    <xhtml:link rel="alternate" hreflang="en" href="https://example.com/en/pricing/"/>
    <xhtml:link rel="alternate" hreflang="de" href="https://example.com/de/preise/"/>
  </url>
  <url>
    <loc>https://example.com/de/preise/</loc>
    <xhtml:link rel="alternate" hreflang="fr" href="https://example.com/fr/tarifs/"/>
    <xhtml:link rel="alternate" hreflang="en" href="https://example.com/en/pricing/"/>
    <xhtml:link rel="alternate" hreflang="de" href="https://example.com/de/preise/"/>
  </url>
</urlset>
```

Codes take the form `language` or `language-REGION`: `fr`, `fr-CH`, `en-GB` (never `en-UK`), `pt-BR`. A country on its own (`be`, `ch`) is not accepted. Details in [validate ISO 639-1 language codes](https://checklist-seo-geo.com/en/hreflang-regional-variants/validate-iso-639-1-language-codes) and [validate country codes](https://checklist-seo-geo.com/en/hreflang-regional-variants/validate-iso-3166-1-alpha-2-country-codes).

> **Warning:** the tags must sit inside a valid `<head>`. A disallowed element placed before them (an `<img>` or `<div>` tag injected by a script) closes the `<head>` as far as the browser and Google are concerned, and the annotations that follow are lost.

### Apache

Versions: Apache 2.4.

HTML pages get their tags from the CMS or framework; Apache only comes into play for non-HTML files, with the `Link` header (`sudo a2enmod headers`):

```apache
<If "%{REQUEST_URI} == '/fr/guide.pdf' || %{REQUEST_URI} == '/en/guide.pdf'">
    Header set Link "<https://example.com/fr/guide.pdf>; rel=\"alternate\"; hreflang=\"fr\", <https://example.com/en/guide.pdf>; rel=\"alternate\"; hreflang=\"en\""
</If>
```

`Header set` replaces an existing `Link` header, a canonical for example: in that case, put all the values on the same line. Reload with `sudo apachectl configtest && sudo systemctl reload apache2`. The block also works in the `.htaccess` file of a shared hosting account.

### Nginx

Versions: Nginx 1.24 and later.

Same principle for PDFs, in the `server` block:

```nginx
location ~ ^/(fr|en)/guide\.pdf$ {
    add_header Link '<https://example.com/fr/guide.pdf>; rel="alternate"; hreflang="fr", <https://example.com/en/guide.pdf>; rel="alternate"; hreflang="en"';
}
```

`sudo nginx -t && sudo systemctl reload nginx`, then check with `curl -sI`.

### Cloudflare

Versions: Cloudflare Workers, all plans including Free, November 2026.

Cloudflare passes the origin's tags and headers through unchanged: the right place for the annotations is still the application. If you cannot touch the templates, a Worker can insert them with `HTMLRewriter`, from a table you keep up to date:

```js
const GROUPS = [
  { fr: '/fr/tarifs/', en: '/en/pricing/', de: '/de/preise/' },
  { fr: '/fr/contact/', en: '/en/contact/', de: '/de/kontakt/' },
];

export default {
  async fetch(request) {
    const response = await fetch(request);
    const url = new URL(request.url);
    const type = response.headers.get('content-type') || '';
    const group = GROUPS.find((g) => Object.values(g).includes(url.pathname));

    if (!group || !type.includes('text/html')) {
      return response;
    }

    const tags = Object.entries(group)
      .map(([lang, path]) => `<link rel="alternate" hreflang="${lang}" href="${url.origin}${path}">`)
      .join('');

    return new HTMLRewriter()
      .on('head', { element(head) { head.append(tags, { html: true }); } })
      .transform(response);
  },
};
```

Deploy it in `Workers & Pages`, then attach it to the domain's `example.com/*` route.

### AWS

Versions: AWS console, Amazon S3 and CloudFront, November 2026.

On **S3** with **CloudFront**, generate the tags in the HTML files at build time. S3 does not accept an arbitrary `Link` header as metadata: for a PDF, create a response headers policy in CloudFront with a custom `Link` header, and attach it to a behavior whose path pattern targets the file (`/fr/guide.pdf`). Then invalidate the path.

### WordPress

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

WordPress produces no annotations on its own: the multilingual plugin handles them, for each translation linked to its original page. WPML (option to display alternative languages in the HEAD section, enabled by default, in `WPML > Settings`, URL and SEO section, since WPML 5; in `WPML > Languages > SEO Options` in WPML 4), Polylang, TranslatePress and Weglot generate them automatically. Keep a single source: a theme or a second plugin that adds its own tags creates competing lists. Detailed settings in [automate annotations through the CMS](https://checklist-seo-geo.com/en/hreflang-regional-variants/automate-annotations-through-cms).

### Shopify

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

With Shopify Markets, Shopify adds the annotations through `content_for_header`, rendered in the `<head>` of `layout/theme.liquid`, and updates them when you change a market's domains or languages. Leave the automatic hreflang tags option enabled, in `Online Store > Preferences`, in the social sharing and SEO section, and do not add tags in the theme.

### PrestaShop

Versions: PrestaShop 8 and 9, Classic and Hummingbird themes.

The Classic and Hummingbird themes (Hummingbird has been the default theme for new installations since PrestaShop 9.1) generate one tag per active language in `templates/_partials/head.tpl` (`head_hreflang` block). A third-party theme that overrides this file may have removed it: check the source code of a product page.

### Magento

Versions: Magento Open Source and Adobe Commerce 2.4.6 to 2.4.9.

No native setting: use an extension from the Adobe Commerce Marketplace that links store views, CMS pages included.

### Drupal

Versions: Drupal 10 and 11; Hreflang module 8.x-1.x, or 2.x from Drupal 11.1.

The core Content Translation module adds the annotations to translated content pages, in the `<head>` and in an HTTP `Link` header. The contributed Hreflang module covers the other pages (views, homepage).

### Wix

Versions: Wix Multilingual, all plans, November 2026.

Wix Multilingual adds the `hreflang` and `x-default` tags by default. Nothing to code.

### Webflow

Versions: Webflow Localization, add-on to site plans, November 2026.

Webflow Localization generates the tags on publish, in the pages and in the automatic sitemap. Only turn them off to write your own.

### Laravel

Versions: Laravel 10 to 13.

The code is the same everywhere; only the middleware registration changes from Laravel 11 onwards.

**Pages whose translation has its own slug.** The controller provides the published versions of the group, current page included:

```php
$alternates = $page->translations()
    ->where('published', true)
    ->get()
    ->mapWithKeys(fn (Page $translation) => [
        $translation->locale => route('pages.show', [
            'locale' => $translation->locale,
            'slug' => $translation->slug,
        ]),
    ]);
```

`route()` returns an absolute URL built on `APP_URL` or the request host. In `resources/views/partials/hreflang.blade.php`, included in the layout's `<head>`:

```blade
@foreach($alternates as $locale => $url)
    <link rel="alternate" hreflang="{{ $locale }}" href="{{ $url }}">
@endforeach

@isset($alternates['en'])
    <link rel="alternate" hreflang="x-default" href="{{ $alternates['en'] }}">
@endisset
```

**Pages whose URLs differ only by the language prefix** (`/fr/contact`, `/en/contact`). A middleware can compute the group for every route at once. Declare the published languages in `config/app.php` (`'supported_locales' => ['fr', 'en', 'de']`), then create the middleware with `php artisan make:middleware ShareHreflangAlternates`:

```php
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\View;
use Symfony\Component\HttpFoundation\Response;

class ShareHreflangAlternates
{
    public function handle(Request $request, Closure $next): Response
    {
        $route = $request->route();

        if ($route?->getName() !== null && $route->hasParameter('locale')) {
            View::share('alternates', collect(config('app.supported_locales'))
                ->mapWithKeys(fn (string $locale) => [
                    $locale => route($route->getName(), [...$route->parameters(), 'locale' => $locale]),
                ]));
        }

        return $next($request);
    }
}
```

Only use this shortcut if every page really exists in all the declared languages: otherwise, go back to the controller method, which lists only published translations. All that remains is to add the middleware to the `web` group, and that is where the versions differ.

#### Laravel 11 to 13

Since Laravel 11, `app/Http/Kernel.php` no longer exists: middleware is registered in `bootstrap/app.php`.

```php
use App\Http\Middleware\ShareHreflangAlternates;
use Illuminate\Foundation\Configuration\Middleware;

return Application::configure(basePath: dirname(__DIR__))
    // ->withRouting(...)
    ->withMiddleware(function (Middleware $middleware): void {
        $middleware->web(append: [
            ShareHreflangAlternates::class,
        ]);
    })
    // ->withExceptions(...)
    ->create();
```

An application upgraded from Laravel 10 without changing its structure can keep its `Kernel.php`: in that case, follow the next tab.

#### Laravel 10 and earlier

Add the middleware at the end of the `web` group, in `app/Http/Kernel.php`:

```php
protected $middlewareGroups = [
    'web' => [
        // … existing middleware, including SubstituteBindings
        \App\Http\Middleware\ShareHreflangAlternates::class,
    ],

    'api' => [
        // …
    ],
];
```

Then clear the configuration and route caches (`php artisan optimize:clear`) and check the `<head>` of one page in each language.

### Symfony

Versions: Symfony 6.4, 7.4 and 8.x.

With localized routes, the base Twig template can generate the versions of the current route:

```twig
{% set route = app.request.attributes.get('_canonical_route') ?: app.request.attributes.get('_route') %}
{% set params = app.request.attributes.get('_route_params')|default({}) %}
{% for locale in ['fr', 'en', 'de'] %}
    <link rel="alternate" hreflang="{{ locale }}" href="{{ url(route, params|merge({'_locale': locale})) }}">
{% endfor %}
```

`url()` produces an absolute URL, unlike `path()`. If a translation may be missing, pass the list of published versions from the controller instead.

### Next.js

Versions: Next.js 15 and 16 (App Router); Next.js 13 to 16 (Pages Router).

#### App Router

Declare `metadataBase: new URL('https://example.com')` in `app/layout.tsx`, then return the versions in `alternates.languages`:

```ts
// app/[lang]/[slug]/page.tsx
import type { Metadata } from 'next';
import { getPageTranslations } from '@/lib/cms';

export async function generateMetadata({ params }: PageProps<'/[lang]/[slug]'>): Promise<Metadata> {
  const { lang, slug } = await params;
  const languages = await getPageTranslations(lang, slug);

  return {
    alternates: {
      canonical: languages[lang],
      languages: { ...languages, ...(languages.en && { 'x-default': languages.en }) },
    },
  };
}
```

`getPageTranslations` returns, for example, `{ fr: '/fr/tarifs/', en: '/en/pricing/', de: '/de/preise/' }`; Next.js prefixes these paths with `metadataBase` and writes one `<link rel="alternate" hreflang>` tag per entry. The global `PageProps` type exists since Next.js 15.5; before that, type `params` as `Promise<{ lang: string; slug: string }>`.

#### Pages Router

The Pages Router has no metadata API, and its `i18n` routing in `next.config.js` writes no `hreflang` tags. Load the versions in `getStaticProps` or `getServerSideProps`, then render them with `next/head`:

```tsx
// components/Hreflang.tsx
import Head from 'next/head';

const SITE = 'https://example.com';

export function Hreflang({ languages }: { languages: Record<string, string> }) {
  return (
    <Head>
      {Object.entries(languages).map(([lang, path]) => (
        <link key={lang} rel="alternate" hrefLang={lang} href={`${SITE}${path}`} />
      ))}
      {languages.en && (
        <link key="x-default" rel="alternate" hrefLang="x-default" href={`${SITE}${languages.en}`} />
      )}
    </Head>
  );
}
```

React expects the `hrefLang` attribute; the server-rendered HTML does contain `hreflang`.

### Nuxt

Versions: Nuxt 4, @nuxtjs/i18n module 10.

With `@nuxtjs/i18n`, set `baseUrl` and a `language` property for each locale in `nuxt.config.ts` (the value is used as the `hreflang` code), then render the links in `app/app.vue` (`app.vue` at the root for a project still on the Nuxt 3 structure):

```html
<script setup>
const head = useLocaleHead()
</script>

<template>
  <Head>
    <template v-for="link in head.link" :key="link.key">
      <Link :id="link.key" :rel="link.rel" :href="link.href" :hreflang="link.hreflang" />
    </template>
  </Head>
  <NuxtPage />
</template>
```

For pages with translated slugs, provide each language's parameters with `useSetI18nParams`.

### Astro

Versions: Astro 5 to 7, @astrojs/sitemap integration 3.

Astro does not write `hreflang` tags in pages. Create a `src/components/Hreflang.astro` component called in the layout's `<head>`:

```html
---
const { alternates } = Astro.props;
---
{Object.entries(alternates).map(([lang, path]) => (
  <link rel="alternate" hreflang={lang} href={new URL(path, Astro.site).href} />
))}
```

`Astro.site` comes from the `site` option in `astro.config.mjs`. Alternative: the `i18n` option of `@astrojs/sitemap`, which writes the annotations into the sitemap when paths are identical from one language to another (`/fr/contact/`, `/en/contact/`).

## Common mistakes

- **Pointing to a language's homepage** when the equivalent page does not exist: simply remove the missing language from the group.
- **Leaving out the current page** from its own list: see [include the self-referencing annotation](https://checklist-seo-geo.com/en/hreflang-regional-variants/include-self-referencing-annotation).
- **Relative URLs** (`/en/pricing/`) or URLs without a protocol: see [use absolute URLs](https://checklist-seo-geo.com/en/hreflang-regional-variants/use-absolute-urls).
- **Targets that redirect, return 404, carry `noindex`** or are canonicalized to another language: the annotation is lost.
- **Two methods or two plugins running in parallel** that do not say the same thing.
- **Annotations added only by JavaScript**: Google may read them after rendering, other crawlers will not.
- **Made-up codes**: `en-UK`, `jp`, `es-419`, `fr_FR` with an underscore.

## Frequently asked questions

### Is hreflang mandatory for a multilingual site?

No, hreflang is not mandatory, but it is recommended as soon as the same page exists in several languages or for several countries. Without annotations, Google may show a version in the wrong language or treat two similar regional variants as duplicates. For a site translated into two very different languages, the effect is modest; for variants of the same language, such as fr-FR and fr-CH, it is decisive.

### Should hreflang go in the HTML, the HTTP header or the sitemap?

Choose a single method: Google treats link tags in the head, the HTTP Link header and the XML sitemap the same way. HTML suits most sites and is easy to check. The HTTP header is for non-HTML files such as PDFs. The sitemap suits sites with many languages or templates that are hard to change. Combining several methods adds nothing and multiplies inconsistencies.

### Does hreflang improve rankings?

No, hreflang is not a ranking factor. It tells Google which version of a page to show based on the searcher's language and country, among pages that are already indexed. The benefits are indirect: a better click-through rate when the right country and language are shown, fewer bounces, and similar regional variants that no longer compete with each other in the results.

### Do ChatGPT or Perplexity use hreflang tags?

No generative engine, whether ChatGPT, Perplexity or Claude, documents any use of hreflang annotations. Their crawlers read the content of each URL, and a translated page at its own address remains citable in its language. The effect is at best indirect: Google's AI Overviews rely on Google's index, which uses hreflang. No annotation guarantees that a specific version will be cited.

### Does Bing take hreflang into account?

Bing reads hreflang annotations, but Fabrice Canel of the Bing team described them in 2020 as a much weaker signal than the content-language tag for that search engine. Bing also infers a page's language and market from its content, its links and its visitors. Keep hreflang for Google and check in Bing Webmaster Tools that each version is properly indexed.

## Resources

- [Google Search Central: Tell Google about localized versions of your page](https://developers.google.com/search/docs/specialty/international/localized-versions?hl=en)
- [Google Search Central: Managing multi-regional and multilingual sites](https://developers.google.com/search/docs/specialty/international/managing-multi-regional-sites?hl=en)
- [Google: The International Targeting report is deprecated](https://support.google.com/webmasters/answer/12474899?hl=en)
- [Shopify: Use hreflang tags in your theme](https://shopify.dev/docs/storefronts/themes/seo/hreflang)
- [Next.js: the alternates field of generateMetadata](https://nextjs.org/docs/app/api-reference/functions/generate-metadata#alternates)
- [Nuxt i18n: SEO and hreflang](https://i18n.nuxtjs.org/docs/guide/seo)
- [Astro: the i18n option of @astrojs/sitemap](https://docs.astro.build/en/guides/integrations-guide/sitemap/)
- [Cloudflare Workers: HTMLRewriter](https://developers.cloudflare.com/workers/runtime-apis/html-rewriter/)

Next steps: [Check reciprocity](https://checklist-seo-geo.com/en/hreflang-regional-variants/check-reciprocity), [Use x-default if relevant](https://checklist-seo-geo.com/en/hreflang-regional-variants/use-x-default-if-relevant) and [Align hreflang and canonical](https://checklist-seo-geo.com/en/hreflang-regional-variants/align-hreflang-canonical).
