Check 23.15 · Hreflang and regional variants

Use HTTP headers for PDFs if needed

Announce the language versions of your PDFs with the HTTP Link header on Apache, Nginx, IIS, Cloudflare, CloudFront, Netlify, Vercel or Laravel.

Priority
Critical
Difficulty
Intermediate
Estimated time
1 to 3 h
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

A PDF has no <head>: you cannot put a <link rel="alternate" hreflang> tag in it. To link the French, German and English versions of the same document, Google accepts the same information in an HTTP Link header sent with the file. Once the task is done, each translated PDF responds with a header that lists every version of the document, including itself.

Why it matters

Google indexes PDFs and can show them in its results. When the same guide exists in several languages, nothing indicates, without annotations, that these files are translations of one another: a German-speaking user may be offered the French version, or the two versions may compete with each other.

Google documents three equivalent ways to declare localized versions: HTML tags, HTTP headers and sitemap. It presents HTTP headers as the solution for non-HTML files, using PDFs as the example. The format is the same as for the tags: a list of URLs with rel="alternate" and an hreflang code, in a single Link header.

The “if needed” in the title matters. The task only concerns PDFs that meet three conditions: they exist in several languages, they are indexable, and they are meant to attract search traffic (data sheets, guides, white papers, documentation). An order form or terms and conditions downloaded from a page do not need it.

What it improves

  • Version served Google can offer the PDF in the user's language or for their country.
  • Competition between files Translations of the same document are recognized as a group rather than as separate documents.
  • Generative engines None documents any use of hreflang. A PDF served well in Google or Bing may be picked up by the engines that rely on those indexes; this is indirect and not guaranteed.
  • Rankings No direct effect.

How to check

Read the headers of each version of the PDF:

curl -sI https://example.com/fr/docs/guide-installation.pdf | grep -i '^link:'

Expected result, on a single line:

link: <https://example.com/fr/docs/guide-installation.pdf>; rel="alternate"; hreflang="fr", <https://example.com/de/docs/installationsanleitung.pdf>; rel="alternate"; hreflang="de", <https://example.com/en/docs/installation-guide.pdf>; rel="alternate"; hreflang="en", <https://example.com/en/docs/installation-guide.pdf>; rel="alternate"; hreflang="x-default"

Repeat on each version: the list must be identical everywhere, and every URL listed must return 200. Also check that the header does not appear on PDFs that are not translated.

Screaming Frog reads hreflang annotations sent through HTTP headers: a crawl that includes PDFs shows them in the Hreflang tab, along with missing return links.

Good to know: curl sends a HEAD request with -I. If a server or CDN responds differently to HEAD and GET, test with curl -s -D - -o /dev/null URL.

How to implement

Before you start

Prepare a table of the documents and their versions:

Group Language (hreflang) URL
guide-installation fr https://example.com/fr/docs/guide-installation.pdf
guide-installation de https://example.com/de/docs/installationsanleitung.pdf
guide-installation en https://example.com/en/docs/installation-guide.pdf
guide-installation x-default https://example.com/en/docs/installation-guide.pdf

Rules:

  • A single header per file, listing every version separated by commas, including the file itself.
  • Absolute URLs, final, with no redirect.
  • The same codes as for pages: fr, de-CH, en-GB.
  • One stable URL per version: if the file name changes with each update (guide-v3.pdf), the annotations break. Keep a fixed name and replace the file.

You can add a canonical to the same header, which Google also accepts through an HTTP header for PDFs: <https://example.com/fr/docs/guide-installation.pdf>; rel="canonical", at the start of the list, with each file pointing to itself.

The Link header is the only method possible in the file itself, but not the only method possible: the sitemap also accepts xhtml:link annotations. If your sitemap is already generated automatically and can include PDFs, it is often easier to maintain. Do not use both without generating them from the same source: see check consistency across HTML, HTTP header and sitemap methods (opens in a new tab).

Apache

Versions Apache 2.4 (<If> blocks do not exist in 2.2).

In the .htaccess file at the root or in the virtual host, with mod_headers enabled (sudo a2enmod headers). An <If> condition on the file paths, with the same value for all of them:

<IfModule mod_headers.c>
    <If "%{REQUEST_URI} in { '/fr/docs/guide-installation.pdf', '/de/docs/installationsanleitung.pdf', '/en/docs/installation-guide.pdf' }">
        Header set Link '<https://example.com/fr/docs/guide-installation.pdf>; rel="alternate"; hreflang="fr", <https://example.com/de/docs/installationsanleitung.pdf>; rel="alternate"; hreflang="de", <https://example.com/en/docs/installation-guide.pdf>; rel="alternate"; hreflang="en", <https://example.com/en/docs/installation-guide.pdf>; rel="alternate"; hreflang="x-default"'
    </If>
</IfModule>

The value is in single quotes to keep the inner double quotes, and fits on a single line. Add one <If> block per document group. Test, then reload:

sudo apachectl configtest && sudo systemctl reload apache2

Nginx

Versions Nginx 1.18 and later; add_header_inherit from 1.29.3.

Two map blocks in the http context: the first maps each file to its group, the second maps each group to its header value.

map $uri $pdf_groupe {
    default                               "";
    /fr/docs/guide-installation.pdf       guide-installation;
    /de/docs/installationsanleitung.pdf   guide-installation;
    /en/docs/installation-guide.pdf       guide-installation;
}

map $pdf_groupe $pdf_hreflang {
    default            "";
    guide-installation '<https://example.com/fr/docs/guide-installation.pdf>; rel="alternate"; hreflang="fr", <https://example.com/de/docs/installationsanleitung.pdf>; rel="alternate"; hreflang="de", <https://example.com/en/docs/installation-guide.pdf>; rel="alternate"; hreflang="en", <https://example.com/en/docs/installation-guide.pdf>; rel="alternate"; hreflang="x-default"';
}

In the server block:

location ~* \.pdf$ {
    add_header Link $pdf_hreflang;
}

Nginx does not send the header when the value is empty: PDFs that are not listed receive nothing. An add_header in a location cancels those inherited from the server block: repeat your security headers there, or, since Nginx 1.29.3 (stable branch 1.30 and later), add add_header_inherit merge; in that location to keep them. Reload with sudo nginx -t && sudo systemctl reload nginx.

Beyond a few documents, generate the two map blocks from a CSV file (group, hreflang, URL) with a script, rather than writing them by hand.

LiteSpeed

Versions LiteSpeed Web Server (Enterprise edition) 6.x, OpenLiteSpeed 1.7 and 1.8.

The method depends on the edition: only the Enterprise edition applies Header directives from .htaccess.

LiteSpeed Enterprise

LiteSpeed reads mod_headers directives from .htaccess. Put the full value in a Header set Link '…' inside a <Files "guide-installation.pdf"> block in the .htaccess of each language folder, then check with curl: support for <If> conditions depends on the version.

OpenLiteSpeed

OpenLiteSpeed only applies the rewrite rules from .htaccess: a Header set there is ignored. In the WebAdmin console, open Virtual Hosts > your host > Context, add a context of type Static with the URI exp:^/(fr/docs/guide-installation|de/docs/installationsanleitung|en/docs/installation-guide)\.pdf$, the location $DOC_ROOT/$0 and Accessible set to Yes. In the Header Operations field, use the same syntax as mod_headers, without the word Header:

set Link '<https://example.com/fr/docs/guide-installation.pdf>; rel="alternate"; hreflang="fr", <https://example.com/de/docs/installationsanleitung.pdf>; rel="alternate"; hreflang="de", <https://example.com/en/docs/installation-guide.pdf>; rel="alternate"; hreflang="en", <https://example.com/en/docs/installation-guide.pdf>; rel="alternate"; hreflang="x-default"'

Save, perform a Graceful Restart, then check with curl.

IIS

Versions IIS 10 (Windows Server 2016 to 2025).

In the site's web.config, one location block per file:

<configuration>
  <location path="fr/docs/guide-installation.pdf">
    <system.webServer>
      <httpProtocol>
        <customHeaders>
          <add name="Link" value="&lt;https://example.com/fr/docs/guide-installation.pdf&gt;; rel=&quot;alternate&quot;; hreflang=&quot;fr&quot;, &lt;https://example.com/de/docs/installationsanleitung.pdf&gt;; rel=&quot;alternate&quot;; hreflang=&quot;de&quot;, &lt;https://example.com/en/docs/installation-guide.pdf&gt;; rel=&quot;alternate&quot;; hreflang=&quot;en&quot;, &lt;https://example.com/en/docs/installation-guide.pdf&gt;; rel=&quot;alternate&quot;; hreflang=&quot;x-default&quot;" />
        </customHeaders>
      </httpProtocol>
    </system.webServer>
  </location>
</configuration>

In an XML file, <, > and " are written &lt;, &gt; and &quot;. Repeat the block for the other two files, with the same value.

Cloudflare

Versions Cloudflare dashboard, all plans, November 2026.

Open the Rules overview, then Create rule > Response Header Transform Rule.

  1. Name: hreflang guide installation.
  2. Custom expression:
http.request.uri.path in {"/fr/docs/guide-installation.pdf" "/de/docs/installationsanleitung.pdf" "/en/docs/installation-guide.pdf"}
  1. “Set static” operation, header name Link, value: the full list, as in the example in the “How to check” section.
  2. Deploy, then test with curl.

One rule per document group. The number of rules available depends on the plan: beyond that, set the header at the origin.

AWS

Versions CloudFront Functions (JavaScript runtimes 1.0 and 2.0) and S3, AWS console, November 2026.

S3 does not let you add a Link header to an object: its system metadata is limited to a few headers (Content-Type, Cache-Control, Content-Disposition…). Go through CloudFront, with a CloudFront Function associated with the viewer-response event of the *.pdf behavior:

var groupes = {
  'guide-installation': '<https://example.com/fr/docs/guide-installation.pdf>; rel="alternate"; hreflang="fr", <https://example.com/de/docs/installationsanleitung.pdf>; rel="alternate"; hreflang="de", <https://example.com/en/docs/installation-guide.pdf>; rel="alternate"; hreflang="en", <https://example.com/en/docs/installation-guide.pdf>; rel="alternate"; hreflang="x-default"'
};

var fichiers = {
  '/fr/docs/guide-installation.pdf': 'guide-installation',
  '/de/docs/installationsanleitung.pdf': 'guide-installation',
  '/en/docs/installation-guide.pdf': 'guide-installation'
};

function handler(event) {
  var response = event.response;
  var groupe = fichiers[event.request.uri];

  if (groupe) {
    response.headers['link'] = { value: groupes[groupe] };
  }

  return response;
}

In the CloudFront console: Functions > Create function, paste the code, publish, then associate it with the relevant behavior, event type “Viewer response”. A response headers policy does not work here: its value is the same for every file in the behavior.

Plesk

Versions Plesk Obsidian 18.0.

Open Websites & Domains > your domain > Apache & nginx Settings. If Nginx serves static files directly, paste the location ~* \.pdf$ block from the Nginx section into “Additional nginx directives”; the map blocks must then be added by the administrator to the global Nginx configuration. Otherwise, use the .htaccess from the Apache section, removing the pdf extension from the list of files served directly by Nginx.

cPanel

Versions cPanel & WHM 110 and later, Jupiter theme.

Open Files > File Manager, show hidden files, paste the block from the Apache section into public_html/.htaccess, then test with curl.

Shared hosting

The .htaccess from the Apache section works with most Apache or LiteSpeed hosts that allow mod_headers. If the header does not appear, ask support whether mod_headers is enabled, or set the header with a Cloudflare rule in front of the site.

Netlify

Versions Netlify, all plans, November 2026.

In the _headers file at the root of the publish directory, one block per file, the value on a single line:

/fr/docs/guide-installation.pdf
  Link: <https://example.com/fr/docs/guide-installation.pdf>; rel="alternate"; hreflang="fr", <https://example.com/de/docs/installationsanleitung.pdf>; rel="alternate"; hreflang="de", <https://example.com/en/docs/installation-guide.pdf>; rel="alternate"; hreflang="en", <https://example.com/en/docs/installation-guide.pdf>; rel="alternate"; hreflang="x-default"

Repeat for the other two URLs, then redeploy.

Vercel

Versions Vercel, all plans, November 2026.

In vercel.json, one entry per file:

{
  "headers": [
    {
      "source": "/fr/docs/guide-installation.pdf",
      "headers": [
        {
          "key": "Link",
          "value": "<https://example.com/fr/docs/guide-installation.pdf>; rel=\"alternate\"; hreflang=\"fr\", <https://example.com/de/docs/installationsanleitung.pdf>; rel=\"alternate\"; hreflang=\"de\", <https://example.com/en/docs/installation-guide.pdf>; rel=\"alternate\"; hreflang=\"en\", <https://example.com/en/docs/installation-guide.pdf>; rel=\"alternate\"; hreflang=\"x-default\""
        }
      ]
    }
  ]
}

WordPress

Versions WordPress 6.4 to 7.1.

Multilingual plugins annotate pages, not Media Library files: PDFs in wp-content/uploads are served directly by the server, without going through WordPress. Set the header at server level (Apache or Nginx sections), with the files' real paths, for example /wp-content/uploads/2026/03/guide-installation.pdf. Replacing a PDF with a new upload changes its URL: use a media replacement plugin that keeps the URL, or update the rules.

Shopify

Versions Shopify admin, all plans, November 2026.

Files uploaded to Shopify are served by its CDN, with no way to add headers. The same limit applies on Wix, Squarespace and Webflow. Instead, publish one HTML page per language that presents the document and offers the PDF as a download: the page carries the hreflang annotations generated by the platform.

Laravel

Versions Laravel 10 to 13: the code does not depend on the version.

If the PDFs go through a route (private files, tracked downloads), add the header to the response:

// app/Http/Controllers/DocumentsController.php
public function show(Document $document): BinaryFileResponse
{
    $link = $document->translations()
        ->where('is_published', true)
        ->get()
        ->map(fn (Document $translation): string => "<{$translation->url}>; rel=\"alternate\"; hreflang=\"{$translation->hreflang}\"")
        ->implode(', ');

    return response()->file(storage_path("app/documents/{$document->path}"), [
        'Content-Type' => 'application/pdf',
        'Link' => $link,
    ]);
}

Import Symfony\Component\HttpFoundation\BinaryFileResponse. translations() must return every version in the group, including the current document. If the PDFs are in public/, they do not go through Laravel: use the Nginx configuration.

Next.js

Versions Next.js 15 and 16, App Router as well as Pages Router.

For files in the public folder, declare the header in next.config.js (in next.config.ts, replace module.exports = with export default):

const hreflangGuide = [
  ['fr', 'https://example.com/fr/docs/guide-installation.pdf'],
  ['de', 'https://example.com/de/docs/installationsanleitung.pdf'],
  ['en', 'https://example.com/en/docs/installation-guide.pdf'],
  ['x-default', 'https://example.com/en/docs/installation-guide.pdf'],
]
  .map(([lang, url]) => `<${url}>; rel="alternate"; hreflang="${lang}"`)
  .join(', ');

module.exports = {
  async headers() {
    return ['/fr/docs/guide-installation.pdf', '/de/docs/installationsanleitung.pdf', '/en/docs/installation-guide.pdf'].map(
      (source) => ({ source, headers: [{ key: 'Link', value: hreflangGuide }] }),
    );
  },
};

Common mistakes

  • Forgetting the file itself in its own list: each PDF must reference itself, just like a page.
  • Several competing Link headers: a server rule and a CDN rule each add their own list. Keep a single source.
  • A value split over several lines in a configuration file that does not allow it: the header is truncated or rejected.
  • Badly escaped quotes: in JSON, XML or an Apache string, one unescaped quote breaks the whole value. Always test with curl.
  • Versioned PDF URLs (guide-v3.pdf): every update breaks the annotations.
  • Annotating PDFs set to noindex (through X-Robots-Tag): a non-indexable target has no place in an hreflang group.
  • Annotating PDFs that are not translations of one another, for example the French product sheet and the full German catalog.

Frequently asked questions

Can you use hreflang on a PDF file?

Yes, with the HTTP Link header. Since a PDF has no head section, Google accepts that the server sends with the file a Link header listing each language version with rel="alternate" and an hreflang code, including the file itself. Google presents this as the method for non-HTML files, and gives PDFs as an example. A sitemap with xhtml:link annotations remains another option.

Should every PDF on a multilingual site be annotated?

No, only those that exist in several languages, are indexable and are meant to attract search traffic: guides, data sheets, white papers, documentation. A PDF available in a single language, or an administrative document downloaded from a page, does not need it. If the content really matters for search, an HTML version of the page is often more useful than a PDF.

How do you add an hreflang header to a PDF on Shopify or Wix?

You cannot: files uploaded to Shopify, Wix, Squarespace or Webflow are served by the platform's CDN, with no control over HTTP headers. The solution is to publish one HTML page per language that presents the document and offers the PDF as a download. These pages receive the hreflang annotations generated by the platform, and become the entry point from search engines.

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