In short
The Accept-Language header states the browser's preferred languages (de-DE,de;q=0.9,en;q=0.8). Googlebot leaves it out. The task is to request the site's pages without this header, then with empty, generic, unsupported or malformed values, and to check that each response stays correct: no server error, no redirect on inner pages, the default language on the root. Once the task is done, a missing or odd header changes nothing in what a crawler receives.
Why it matters
Google states it in its documentation on locale-adaptive pages: its crawler sends HTTP requests without setting Accept-Language, and its default IP addresses appear to be located in the United States. Bing and generative engine crawlers do not document this point. A site that only behaves well with a browser set to a specific language is therefore tested in a configuration its most important crawlers do not use.
Defects that appear without the header, or with an unexpected value:
- Server error: the code reads the first language in the header without checking that it exists. In PHP, a missing
$_SERVER['HTTP_ACCEPT_LANGUAGE']triggers a warning, which the framework sometimes turns into a 500 error. - Negotiation exception: some libraries throw an error on a
*or invalid value. Next.js projects have reported aRangeErrorthrown by@formatjs/intl-localematcherwhen the resulting language list contained*. - Unexpected redirect: with no preference, the code redirects to the default language, even from a German page.
- Arbitrary language: the root serves the language of the last cached visitor, or a language that was not planned.
This test complements the redirect test: avoid forced redirects based on browser language (opens in a new tab) deals with the decision to redirect, this guide with how robust the code is when handling the header.
What it improves
- Crawling No more 5xx errors or redirects that only crawlers get.
- Indexing of each language Each URL responds in its language, with or without the header.
- x-default The root serves a predictable version, which hreflang annotations can point to.
- Robustness Unusual clients (monitoring tools, link previews, AI crawlers) receive a correct response.
- Rankings No direct effect.
How to check
curl sends no Accept-Language header by default: that is Googlebot's situation. This script compares several variants on the same URL:
#!/usr/bin/env bash
# Usage: bash test-accept-language.sh https://example.com/de/preise/
url="$1"
check() {
label="$1"
shift
body=$(mktemp)
result=$(curl -s -o "$body" -w '%{http_code} %{redirect_url}' "$@" "$url")
lang=$(grep -o -i '<html[^>]*lang="[^"]*"' "$body" | head -n 1 | sed -E 's/.*lang="([^"]*)".*/\1/')
printf '%-16s %-40s lang=%s\n' "$label" "$result" "${lang:-missing}"
rm -f "$body"
}
check "missing"
check "empty" -H "Accept-Language;"
check "asterisk" -H "Accept-Language: *"
check "unsupported" -H "Accept-Language: ja-JP,ja;q=0.9"
check "region only" -H "Accept-Language: de-CH"
check "malformed" -H "Accept-Language: xx;q=abc,,;"
check "browser fr" -H "Accept-Language: fr-FR,fr;q=0.9,en;q=0.8"
In curl, -H "Accept-Language;" sends an empty header, whereas -H "Accept-Language:" removes it. Run the script on the root, then on a deep page in each language.
Expected result:
| URL tested | All variants |
|---|---|
Inner page (/de/preise/) |
200, no redirect, the URL's lang, identical on every line |
Root (/) |
200 on the choice page or the default language when the header is missing, empty, *, unsupported or malformed; possibly a 302 to a recognized language for de-CH or fr-FR |
Also check the application's error logs during the test: a warning repeated on every request without the header ends up filling the logs and hiding the real problems.
How to implement
Before you start
Three rules for any code that reads Accept-Language:
- Only read it where it is useful: the root or a suggestion banner. Never to choose the language of an inner page.
- Always plan a default: a missing, empty or
*header, or one with no supported language, gives the default language, with no error. - Limit the result to your languages: the value obtained must belong to the list of published languages before it is used to build a URL.
The root must be consistent with the x-default annotation: see use x-default if relevant (opens in a new tab) and define the default version (opens in a new tab).
PHP without a framework
<?php
function preferredLocale(array $supported, string $default): string
{
$header = $_SERVER['HTTP_ACCEPT_LANGUAGE'] ?? '';
if ($header === '') {
return $default;
}
foreach (explode(',', $header) as $part) {
$code = strtolower(substr(trim(explode(';', $part)[0]), 0, 2));
if (in_array($code, $supported, true)) {
return $code;
}
}
return $default;
}
$locale = preferredLocale(['fr', 'de', 'en'], 'fr');
This simple version follows the order of the header and ignores the q weights, which is enough to route visitors at the root. The intl extension offers Locale::acceptFromHttp(), which can return false or a language missing from your list: always check its result.
Apache
Versions Apache 2.4.
Routing at the root in .htaccess must end with an unconditional rule, which covers the missing header:
RewriteEngine On
RewriteCond %{HTTP:Accept-Language} ^de [NC]
RewriteRule ^$ /de/ [R=302,L]
RewriteCond %{HTTP:Accept-Language} ^en [NC]
RewriteRule ^$ /en/ [R=302,L]
RewriteRule ^$ /fr/ [R=302,L]
Without the last line, a request without the header receives the root's index file, which may be empty or different from the intended default version. Also check that MultiViews is not enabled on content folders.
Nginx
Versions Nginx 1.24 and later.
In a map table, the default line covers the missing header and unrecognized values:
map $http_accept_language $preferred_lang {
default fr;
~*^de de;
~*^en en;
}
Without default, the variable is empty and the redirect leads to //. Reload with sudo nginx -t && sudo systemctl reload nginx.
Cloudflare
Versions Cloudflare dashboard, Workers and Redirect Rules, all plans, November 2026.
In a Worker, request.headers.get('accept-language') returns null when the header is missing. Set the default value before any processing:
const header = (request.headers.get('accept-language') || '').toLowerCase();
const lang = ['de', 'en'].find((code) => header.startsWith(code)) || 'fr';
In redirect rules, an expression such as starts_with(http.request.headers["accept-language"][0], "de") is false when the header is missing: add a final rule for the root with no language condition. Check the order of the rules in the Rules overview.
AWS
Versions CloudFront Functions (JavaScript runtimes 1.0 and 2.0) and Lambda@Edge, AWS console, November 2026.
In a CloudFront Function, request.headers['accept-language'] is undefined when the header is missing: check that it exists before reading .value, otherwise the function fails and CloudFront returns an error. Lambda@Edge exposes an array of objects per header, with the same precaution. Publish the function, then run the script again.
WordPress
Versions WordPress 6.8 to 7.1, with Polylang 3.x or WPML 4.8 and 4.9.
- Polylang: browser language detection only applies to the home page; without the header, the default language is served. Test the home page and a deep page in each language.
- WPML: with redirection based on browser language enabled, check that a request without the header stays on the requested page.
- Custom code: search for
HTTP_ACCEPT_LANGUAGEinwp-contentand protect each read with?? ''and a default value.
Laravel
Versions Laravel 11 to 13; mcamara/laravel-localization 2.x package.
$request->getPreferredLanguage() returns the first language of the list provided when the header is missing or matches no supported language:
$locale = $request->getPreferredLanguage(['fr', 'de', 'en']);
Put the default language first in the list. With Laravel Localization (mcamara), setting useAcceptLanguageHeader to false removes any dependency on the header.
Symfony
Versions Symfony 6.4, 7.4 and 8.x.
$request->getPreferredLanguage(['fr', 'de', 'en']) follows the same principle: the first language of the list is the fallback. Reserve this call for the root's controller; the other routes take their language from {_locale}.
Next.js
Versions Next.js 16 (proxy.ts) and 15 (middleware.ts).
The documentation example that combines negotiator and @formatjs/intl-localematcher can throw an error on a missing or invalid header, depending on how the headers are passed. Build a plain object and guard the call:
// proxy.ts (middleware.ts before Next.js 16)
import { match } from '@formatjs/intl-localematcher';
import Negotiator from 'negotiator';
import { NextRequest, NextResponse } from 'next/server';
const locales = ['fr', 'de', 'en'];
const defaultLocale = 'fr';
function getLocale(request: NextRequest): string {
const header = request.headers.get('accept-language') ?? '';
const languages = new Negotiator({ headers: { 'accept-language': header } })
.languages()
.filter((language) => language !== '*');
try {
return match(languages, locales, defaultLocale);
} catch {
return defaultLocale;
}
}
export function proxy(request: NextRequest) {
const response = NextResponse.redirect(new URL(`/${getLocale(request)}`, request.url), 302);
response.headers.set('Vary', 'Accept-Language');
return response;
}
export const config = {
matcher: ['/'],
};
With Next.js 15, the file is called middleware.ts and the exported function middleware; the rest of the code is identical. The matcher limits detection to the root. With the Pages Router and localeDetection: false, the header is not used.
Nuxt
Versions Nuxt 4 with the @nuxtjs/i18n 10 module.
With @nuxtjs/i18n, the detectBrowserLanguage.fallbackLocale option sets the language used when none of the browser's languages is supported; without it, the default language applies. Keep redirectOn: 'root' and test the root without the header.
Common mistakes
- Reading
$_SERVER['HTTP_ACCEPT_LANGUAGE']without a fallback value: a warning on every crawler visit, or even a 500 error. - Forgetting the default rule in a cascade of redirects: the root without the header serves an empty or unexpected page.
- Building a URL with the raw language from the header:
/ja/or/*/do not exist, hence a string of 404s. - Testing only from a browser: it always sends a language; only curl or a configured tool reproduces the missing header.
- Redirecting inner pages to the default language when the header is missing: Googlebot no longer sees the other languages.
- Caching the root's response without
Vary: Accept-Language: the first visitor's language is served to everyone.
Frequently asked questions
Does Googlebot send the Accept-Language header?
No, according to Google's documentation on locale-adaptive pages: its crawler sends requests without setting Accept-Language, from IP addresses that appear to be mainly American. A site that chooses a page's language based on this header therefore always shows it the default language. Google recommends separate URLs for each language, annotated with hreflang, so that each version is crawled.
Which language should the root serve when the header is missing?
Serve the version declared as x-default in your hreflang annotations: a language choice page, or the site's default language. The behavior must be the same for a header that is missing, empty, equal to an asterisk, malformed or that contains no supported language. If the root redirects, use a temporary 302 redirect and keep it out of the shared cache.
Can a missing Accept-Language header cause a server error?
Yes, when the code reads the header without checking that it exists or assumes valid syntax. In PHP, the missing index triggers a warning; some JavaScript negotiation libraries throw an exception on a generic or invalid value. Test with curl without the header, with an empty header and with a malformed value, and always provide a default language in the code.
Should you test values other than a missing header?
Yes. At a minimum, test an empty header, the generic asterisk value, a language the site does not offer, a regional variant on its own such as de-CH, and a malformed value. These cases occur with crawlers, monitoring tools, link previews and unusually configured browsers. Every inner page must respond identically in all these cases.
Resources
- Google Search Central: How Google crawls locale-adaptive pagesdevelopers.google.com
- MDN: Accept-Language headerdeveloper.mozilla.org
- W3C: Guiding visitors to translated pagesw3.org
- Next.js: Internationalization (App Router)nextjs.org
- Nuxt i18n: Browser language detectioni18n.nuxtjs.org
- PHP: Locale::acceptFromHttpphp.net
- Cloudflare Workers: Request objectdevelopers.cloudflare.com
Updated on
Topic checklist (PDF)