slop audit
Blog post 66 / Technical SEO and launch readiness

Hreflang tags: setup and testing before website launch

Add hreflang tags for localized pages, fix missing return links and canonical conflicts, and test deployed language variants before your website launches.

By Slop Audit · 8 min read

Hreflang tags connect localized versions of the same page. Before launching a multilingual website, define which URLs belong together, publish the alternate links consistently, and test every member of that group. A correct English page alone cannot prove that the French page links back.

This guide uses a small documentation site with English and French installation guides. You will build its locale map, add HTML annotations, diagnose common deployment mistakes, and keep a focused reciprocal-link check in CI.

Hreflang tags launch checklist

For each translated page, record the intended language, public URL, canonical URL, and matching pages in other languages. Then check:

  1. Each target contains the corresponding content, not an unrelated locale homepage.
  2. The HTML head lists the group, including the current page.
  3. Each linked version returns the relationship.
  4. URLs are absolute and use the published hostname and path spelling.
  5. Language and region codes match Google's supported format.
  6. Canonicals, crawl rules, and indexing directives support the intended release.
  7. The deployed response contains the expected annotations.
  8. A visitor can select another language and still reach the corresponding task.

Keep this inventory with the route configuration. When a translation is added, moved, or removed, update the whole group in the same change.

Decide which localized pages belong together

Start with content identity rather than replacing a language prefix in every URL. For example:

Content key: install-guide
English: https://example.com/en/docs/install/
French:  https://example.com/fr/docs/installation/

The French slug differs deliberately. A string replacement from /en/ to /fr/ would invent a route that does not exist. Store the actual paths in a reviewed content map and use that map for metadata and the visible language selector.

If the French installation guide is unfinished, leave it out of this group until it is public. Do not substitute /fr/ just to fill a field. A reader asking how to install the product needs the corresponding instructions, not a homepage in the preferred language.

Google recommends distinct URLs for language versions and warns that automatic language redirects can prevent access to some versions. Its multilingual site guidance also explains that Google determines language from visible text. An annotation cannot translate a page or repair an English fallback served at the French URL.

Keep the HTML lang attribute aligned with the document's language. It serves a separate accessibility and language-processing purpose.

Add a reciprocal hreflang example to the HTML head

For this two-language group, put the following alternate links in the head of both documents:

<link rel="alternate" hreflang="en"
      href="https://example.com/en/docs/install/">
<link rel="alternate" hreflang="fr"
      href="https://example.com/fr/docs/installation/">

Google's localized-version requirements call for self-inclusion, fully qualified URLs, and links in both directions. HTML annotations belong in a well-formed head. Alternate domains are allowed. Google supports HTML, HTTP headers, and XML sitemaps as equivalent annotation methods; choose one you can maintain reliably.

This guide chooses HTML for a small site. Keep one source of truth for each content group and render its links through the shared head template. Avoid separate hand-maintained arrays in each translated page.

Use a language code such as en or fr; add a region when the content actually has a regional target, such as en-GB. Use GB, not UK, and hyphens rather than internal locale underscores. Google's supported codes are narrower than arbitrary BCP 47 tags: do not copy every valid HTML lang value into hreflang without checking support. For example, es-419 is not supported by Google's hreflang guidance.

Before adding regions, ask what changes for the reader. If two routes offer the same English instructions without a regional distinction, a generic English version may be easier to maintain.

Choose x-default and canonical URLs deliberately

x-default identifies a fallback for language settings that do not match the listed variants. Google's x-default introduction describes its use for an international selector or default landing page.

For this installation guide, the product team can choose English as the fallback. Add the same extra entry to both pages:

<link rel="alternate" hreflang="x-default"
      href="https://example.com/en/docs/install/">

This is a fallback choice, not a reason to redirect a French visitor away from an explicitly requested French URL. If you use a selector page instead, make that destination useful for this content group and include it in your relationship checks.

Keep the canonical separate from the alternates. For independently published translations in this example, use the English URL as the English page's canonical and the French URL as the French page's canonical:

<!-- On the French installation guide only -->
<link rel="canonical"
      href="https://example.com/fr/docs/installation/">

Google's canonical guidance recommends a canonical in the same language when available. Do not point every translation at the English original by default. Same-language regional duplicates need a deliberate canonical decision; the self-canonical contract below is specific to this example's independent translations.

Use the canonical URL and redirects guide when hostname, slash, or redirect rules disagree with your locale map.

Diagnose missing return tags and deployed mismatches

When a report identifies missing hreflang return tags, inspect the destination as well as the source. Save both delivered heads and compare their complete locale maps.

A practical debugging order is:

  • Only one language links back: inspect whether its template receives the shared content key. A translated slug may not resolve to the same record.
  • A target redirects: replace the stale URL with the intended final address, then check the return links there.
  • Preview URLs appear in production: fix the public-origin configuration used at build time and rebuild all affected pages.
  • The head contains duplicate locale values: check whether both the framework layout and an SEO plugin emit the group.
  • A valid locale URL shows an error or fallback: repair its route or translation before advertising it as available.
  • Browser inspection differs from the response: compare the initial HTML with changes made during hydration. Remove competing metadata owners.

For an indexable release, review the noindex troubleshooting steps and the deployed robots rules too. Presence of alternate links does not establish crawl access or indexability.

Keep visible language navigation in the test plan. Open the French guide, switch to English, and confirm that the installation instructions remain the destination. Repeat after a direct nested-route load and a refresh.

Add hreflang testing for a known locale cluster

This Playwright Test example checks the two translated documents and their English fallback. It requests each URL without following redirects and parses the response HTML with DOMParser, so client-side metadata cannot hide missing server output.

import { expect, test } from "@playwright/test";

const variants = [
  { language: "en", path: "/en/docs/install/" },
  { language: "fr", path: "/fr/docs/installation/" },
];

test("installation guides publish reciprocal locale links", async ({ request, page }) => {
  const releaseOrigin = process.env.RELEASE_ORIGIN;
  if (!releaseOrigin) throw new Error("Set RELEASE_ORIGIN to this deployment");

  const expected = variants.map(({ language, path }) => ({
    language,
    url: new URL(path, releaseOrigin).href,
  }));
  expected.push({ language: "x-default", url: expected[0].url });

  for (const variant of expected.filter((item) => item.language !== "x-default")) {
    const response = await request.get(variant.url, { maxRedirects: 0 });
    expect(response.status(), variant.url).toBe(200);
    expect(response.headers()["content-type"]).toContain("text/html");

    const actual = await page.evaluate((html) => {
      const doc = new DOMParser().parseFromString(html, "text/html");
      return {
        alternates: Array.from(
          doc.head.querySelectorAll('link[rel~="alternate"][hreflang]'),
          (link) => ({
            language: link.getAttribute("hreflang"),
            url: link.getAttribute("href"),
          }),
        ),
        canonicals: Array.from(
          doc.head.querySelectorAll('link[rel~="canonical"]'),
          (link) => link.getAttribute("href"),
        ),
      };
    }, await response.text());

    expect(actual.alternates, variant.url).toHaveLength(expected.length);
    expect(actual.alternates, variant.url).toEqual(expect.arrayContaining(expected));
    expect(actual.canonicals, variant.url).toEqual([variant.url]);
  }
});

Playwright documents the request options and page.evaluate execution context. The blank browser page provides a parser; the test does not navigate to or execute scripts from the fetched document.

Adapt the routes, public metadata origin, and canonical decisions before use. This fixture assumes a deployment at the origin root whose annotations point to that same deployment. A preview that deliberately advertises production URLs needs separate request and expected-metadata origins; do not rewrite production metadata merely to satisfy a preview test.

Exact set comparison catches missing self-links, missing return links, unexpected locales, relative URLs, and duplicate entries for this group. It does not validate translation quality, every locale code, HTTP-header or sitemap annotations, robots directives, or Google's eventual processing. Add other content groups as reviewed fixtures, then retain a visible-language and navigation check beside this metadata test in your website regression testing workflow.

Check each public page with Slop Audit

After the locale-cluster tests pass, run Slop Audit on each public language URL. Review the observed HTTP response, canonical declaration, title, description, HTML language declaration, and crawler-access findings. Fix the page-specific issues and rescan the same URL so the release record includes the repaired result.

Slop Audit's language check records a non-empty root lang value; its canonical check observes the declaration and origin relationship. These checks do not verify translation accuracy, canonical selection by Google, hreflang codes, reciprocal links, or the full locale cluster. Keep the focused test above with the audit reports. Together they give you a concrete record of the relationship you published and the surrounding launch evidence for each page.