許多網站會根據使用者的語言或
區域。hreflang 連結會將
網頁,這樣他們就能針對各個語言或地區顯示正確版本。
Lighthouse hreflang 稽核失敗的原因
Lighthouse 標記
不正確的 hreflang 連結:
Lighthouse 檢查 hreflang 個連結
網頁的 head 和回應標頭中。
Lighthouse 隨後會檢查 hreflang 連結中的語言代碼是否有效。
Lighthouse 會回報含有無效語言代碼的所有 hreflang 連結,
Lighthouse 不會檢查區碼或 Sitemap。
如何為每個網頁版本定義 hreflang 連結
假設該網頁有三個版本:
- 英文版:https://example.com
- 西班牙文版:https://es.example.com
- 德文版 (https://de.example.com)
有三種方式可以告知搜尋引擎這些網頁是對等網頁。 請根據您的情況選擇最簡單的方法。
方法 1:在每個網頁的 <head> 中加入 hreflang 連結:
<link rel="alternate" hreflang="en" href="https://example.com" />
<link rel="alternate" hreflang="es" href="https://es.example.com" />
<link rel="alternate" hreflang="de" href="https://de.example.com" />
每個網頁版本都必須連結至所有其他版本
否則,搜尋引擎可能會忽略 hreflang 連結
或是誤解
如果網頁可讓使用者選擇語言,請使用x-default
關鍵字:
<link rel="alternate" href="https://example.com" hreflang="x-default" />
選項 2:在 HTTP 回應中新增 Link 標頭:
Link: <https://example.com>; rel="alternate"; hreflang="en", <https://es.example.com>;
rel="alternate"; hreflang="es", <https://de.example.com>; rel="alternate"; hreflang="de"
方法 3:將語言版本資訊新增至 Sitemap。
<url>
<loc>https://example.com</loc>
<xhtml:link rel="alternate" hreflang="es"
href="https://es.example.com"/>
<xhtml:link rel="alternate" hreflang="de"
href="https://es.example.com"/>
</url>
hreflang值的規範
- hreflang值必須一律指定語言代碼。
- 語言代碼必須遵循 ISO 639-1 格式。
- hreflang值也可以包含選用的區域代碼。 例如,- es-mx適用於墨西哥的西班牙文使用者,- es-cl則代表 智利西班牙文使用者。
- 區域代碼必須加上 ISO 3166-1 alpha-2 格式。