Multilingual SEO · · 8 min read

hreflang x-default in Laravel: What It Is For and When to Emit It

A common hreflang setup in a Laravel app looks like this: every page lists en, es and de, and then a fourth line, x-default, that points at the English URL. Someone copied it from a tutorial, it validates, and nobody has thought about it since. Then a team adds a language selector page at the site root, and discovers that the x-default they already ship points at the wrong thing.

x-default is the least understood value in the hreflang set. It is not a language and it is not an alias for your source language. This article covers what the documentation says it is, how to decide which URL it should name, and how to emit it from one place in a Laravel app.

What the documentation says

Google's localized versions guide defines it in one sentence: the reserved x-default value is used when no other language or region matches the user's browser setting. The same page says it was designed for language selector pages, and suggests it for a fallback page for unmatched languages, for example a home page that redirects or lets users pick.

Two things follow from that wording.

First, x-default names a page for people you have no specific answer for. A visitor whose browser asks for Korean, on a site that has en, es and de, matches none of your tags. That visitor is the audience for x-default.

Second, it does not need a language code, because the language of that page is not what matters. It can be English, it can be a page with no running text at all, or it can be a picker.

It is also an ordinary member of the hreflang set. The usual rules apply: absolute URLs, and the set has to be consistent across every version. If you need the refresher on those rules, the original multilingual SEO post covers them, and our BCP 47 glossary entry explains the tag format behind the codes.

Which URL should it name

There are three reasonable answers, and the right one depends on what you have.

A language selector page. If you have a page whose job is to let people choose a language, such as / or /choose-language, that is exactly what the documentation describes. It is the cleanest use.

Your default-language version of the same page. If there is no selector, the common choice is the URL of the version you consider the fallback, usually the source language. For /es/pricing, the x-default entry names /en/pricing. This is what most Laravel apps do, and it is fine. Note that the same URL then appears twice in the set, once as en and once as x-default. That is allowed.

A redirecting URL. Avoid this. If x-default points at /pricing and that URL does a 302 to a negotiated locale, you have asked search engines to treat a redirecting URL as the fallback page. Point at a URL that returns 200 and renders content or a picker.

Which of the first two is better is a judgment call. If your site root is just a redirect, use the default-language page. If you built a real selector, use that, and keep it as a page that is useful to a human who arrived there.

Emitting it from one place

The usual mistake is hand-writing the x-default line per page. Generate the whole set from your locale config, and make the fallback explicit.

// config/locales.php
return [
    'supported' => ['en', 'es', 'de', 'pt-BR'],
    'default' => 'en',

    // What x-default points at: 'default' (the default-locale page)
    // or 'selector' (the language selector route).
    'x_default' => 'default',
];

A small service builds the alternates for a route, so views, sitemaps and tests all agree:

namespace App\Support;

final class HreflangSet
{
    /**
     * @param  array<string, mixed>  $parameters
     * @return array<string, string>  hreflang => absolute URL
     */
    public function for(string $routeName, array $parameters = []): array
    {
        $set = [];

        foreach (config('locales.supported') as $locale) {
            $set[$locale] = route($routeName, [...$parameters, 'locale' => $locale]);
        }

        $set['x-default'] = config('locales.x_default') === 'selector'
            ? route('language.selector')
            : $set[config('locales.default')];

        return $set;
    }
}

And the Blade side is a loop:

{{-- resources/views/components/hreflang.blade.php --}}
@props(['route', 'parameters' => []])

@foreach (app(\App\Support\HreflangSet::class)->for($route, $parameters) as $code => $url)
    <link rel="alternate" hreflang="{{ $code }}" href="{{ $url }}">
@endforeach

route() returns absolute URLs by default, which is what the documentation requires: alternate URLs must be fully qualified, including the protocol. If your app sits behind a proxy and generates http:// links, fix trusted proxies first, or every alternate will carry the wrong scheme.

If you serve hreflang from a sitemap instead of the page head, the same HreflangSet can feed the xhtml:link entries.

The selector route

If you choose the selector option, it has to be a real page that does not redirect:

Route::view('/choose-language', 'language-selector')->name('language.selector');
{{-- resources/views/language-selector.blade.php --}}
<x-layouts.guest>
    <h1>{{ __('Choose your language') }}</h1>

    <ul>
        @foreach (config('locales.supported') as $locale)
            <li>
                <a href="{{ route('home', ['locale' => $locale]) }}" hreflang="{{ $locale }}" lang="{{ $locale }}">
                    {{ \Locale::getDisplayName($locale, $locale) }}
                </a>
            </li>
        @endforeach
    </ul>
</x-layouts.guest>

Plain links, not a form that posts to a controller and sets a cookie. A crawler follows links; it does not submit forms. A cookie-only locale also leaves crawlers seeing a single language, which is the failure the original multilingual SEO post starts from.

Locale::getDisplayName() comes from PHP's intl extension. If you do not have it installed, keep a name map in the config file instead.

One caveat: a selector is only the right x-default if it is where unmatched visitors actually land. If your root redirects by Accept-Language and unmatched visitors end up on the English home page, then that English URL, not the selector, is your fallback page. Name the 200 page that unmatched visitors really receive.

Where it goes wrong

x-default on only some pages. The set is meant to be consistent. If the product pages have it and the blog does not, that is not an error that anyone will report, but the fallback behaviour you wanted is incomplete.

Pointing at a URL that is not in the set otherwise. If x-default names /choose-language, that URL is a member of the set but has no translations of its own. Do not add hreflang annotations to the selector page pointing at each language's home page as if they were translations of it. They are not. The selector can simply have no annotations.

Treating it as a ranking lever. The documentation describes it as a fallback match. It does not say it boosts anything, and we would not expect it to. If you are not seeing a language version in a market, x-default is not the lever to pull.

The wrong scheme or host. An x-default that carries http:// or a staging hostname is a quiet failure. A test catches it faster than Search Console does.

Assuming every engine reads it the same way. Yandex's documentation also describes x-default, for pages where the language is chosen automatically, for example by IP address or the Accept-Language header. Support elsewhere varies, which is why we recommend not building anything that depends on it. Check each engine's own documentation before relying on it.

When you can skip it

If your site has two languages and every page exists in both, the x-default line adds little. A visitor whose browser asks for neither language is going to see one of your two versions anyway, and the tag only states which. Adding it costs nothing, so we still emit it by default. But it is reasonable to leave it out of a small setup rather than build a selector for it.

Where it earns its place is a site with several languages and visitors from places you did not target, or a site with a real root-level picker. In those cases it documents your intent.

A test that pins it

use App\Support\HreflangSet;

it('emits x-default pointing at a url that is also a real locale url', function () {
    config(['locales.x_default' => 'default']);

    $set = app(HreflangSet::class)->for('pricing');

    expect($set)->toHaveKey('x-default')
        ->and($set['x-default'])->toBe($set['en'])
        ->and($set['x-default'])->toStartWith('https://');
});

it('points x-default at the selector when configured', function () {
    config(['locales.x_default' => 'selector']);

    $set = app(HreflangSet::class)->for('pricing');

    expect($set['x-default'])->toBe(route('language.selector'));
});

The https:// assertion assumes your test environment generates secure URLs. If it does not, set APP_URL for the test run or drop that line.

Summary

  • x-default names the page for users whose language you do not match. It is not "the English version".
  • Point it at a selector page or at your default-language version of the same page. Never at a URL that redirects.
  • Generate it with the rest of the set from one locale config, so it cannot drift.
  • Keep the selector a plain, linkable page.
  • It is a fallback hint, not a ranking lever, and a small bilingual site can reasonably skip it.

The selector heading and every language's metadata are translated strings like any other. If one needs a fix, LangSyncer lets you correct it in production without a deploy. For how Laravel chooses a fallback locale for missing strings, which is a different thing from x-default, see the glossary.

More on Multilingual SEO

All Multilingual SEO articles →

We'd like to use analytics and marketing cookies to understand how the site is used. They stay off unless you accept them. Cookie Policy