Перейти к основному содержимому
← 📄 HTML & the platform·Модуль A6 · Урок 9
ЗаданиеAdd hreflang link tags for a 4-language page: en (/post), uk (/uk/post), ru (/ru/post), fr (/fr/post), plus x-default (/post). All absolute URLs starting with https://example.com.

hreflang: 18 языков, одна иерархия URL-адресов.

100 XP8 min
Теория

When you have translated pages

Tell Google "here are sibling versions of this page in other languages, route the user to the right one":

<link rel="alternate" hreflang="en" href="https://example.com/post" />
<link rel="alternate" hreflang="uk" href="https://example.com/uk/post" />
<link rel="alternate" hreflang="ru" href="https://example.com/ru/post" />
<link rel="alternate" hreflang="x-default" href="https://example.com/post" />

Rules

  • Every translated page links to ALL siblings (including itself). If you have 18 langs, you have 19 link tags (18 siblings + 1 x-default) on EVERY page.
  • hreflang values are BCP 47: en, uk, en-US, pt-BR, zh-Hans, x-default.
  • `x-default` = the fallback when the user's language doesn't match any explicit hreflang. Usually points to your English URL.
  • Bidirectional confirmation. The UK page must link back to the EN page. If the link is one-way, Google ignores both.

Why it matters

Without hreflang, Google indexes both /post and /uk/post as separate competing pages. They cannibalize each other's rankings. With hreflang, Google knows they're the same content for different audiences — keeps both indexed, shows the right one based on user locale.

Sitemap alternative

For sites with many translations, listing hreflang in the XML sitemap (one entry per URL with embedded alternates) is more maintainable than emitting 19 link tags per page.

CodeMentor uses both

Our buildHreflangLanguages() helper on every page emits the 18 link tags, AND the sitemap includes hreflang for each URL. Belt + suspenders. Google reads either.

🔒

Зарегистрируйся чтобы кодить

Теория открыта всем. Интерактивный редактор, живой превью и проверка открываются с 7-дневным бесплатным trial — нужна карта, отмена в любое время.

Регистрация — бесплатный trial →

Первые 10 уроков в каждом треке — бесплатные. Карта не нужна.

← НазадСледующий урок →

Получай один совет по Python или веб-разработке — каждый день в почте

Коротко, без воды, без спама. Отписаться — в один клик.