Pauznet
Pauznet

Reputation: 11

Avoid duplicating hreflang tags

How can i avoid duplicating hreflang tags in this situation:

Home : http://mywebsite.com -> use browser language (assuming what is french now)

<link rel=”alternate” hreflang=”fr” href=”http://mywebsite.com”>
<link rel=”alternate” hreflang=”fr” href=”http://mywebsite.com/fr”>
<link rel=”alternate” hreflang=”en” href=”http://mywebsite.com/en”>

Thank you specialists

Upvotes: 1

Views: 158

Answers (2)

Tobias Schwarz
Tobias Schwarz

Reputation: 233

Languages should be unique within a hreflang group, and therefore you should not have multiple URLs for fr within your hreflang definition. I recommend doing the following:

  1. Specify https://example.com/ as x-default so it will be used for all languages without a specification.
<link rel="alternate" hreflang="x-default" href="https://example.com/">
<link rel="alternate" hreflang="fr" href="https://example.com/fr">
<link rel="alternate" hreflang="en" href="https://example.com/en">
  1. Make https://example.com/ a redirect to the best matching language based on the Accept-Language HTTP header (https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language).

When implementing the redirect, you need to be aware of some things:

  1. The redirects used for the redirect to the best matching language should not be cacheable, and therefore you should implement it as an 302, 303 or 307 redirect. Take a look at this redirect status table to understand the differences. Without this, proxy servers with aggressive caching could cache the redirect.
  2. In addition with the redirect, a Vary HTTP header (https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Vary) should be sent to indicate that the behavior of the URL changes based on the Accept-Language HTTP header (Vary: Accept-Language). Without this, search engine robots will not understand that they get a different behavior when accessing this URL with a different Accept-Language` HTTP header.

In addition to these technical aspects, you should be aware that it is not really necessary to implement hreflang for different languages to get the correct language targeting, as search engines do quite well to distinguish languages e.g. French from English. Setting the proper language on the HTML tag <html lang="en"> is usually sufficient, and hreflang can add quite some overhead in terms of file size if you have a lot of different languages. Hreflang however is absolutely necessary when targeting multiple region with the same language e.g. Germany (de-DE), Austria (de-AT) and Switzerland (de-CH).

Note: I also wrote a complete guide on hreflang a while back with a list of common mistakes to avoid.

Upvotes: 0

Julian
Julian

Reputation: 767

You can set the language and region via hreflang.

Examples:

  • de: German language content, independent of region
  • en-GB: English language content, for GB users
  • de-ES: German language content, for users in Spain

Source: https://developers.google.com/search/docs/advanced/crawling/localized-versions

The default specification is then x-default value.

Source: https://developers.google.com/search/blog/2013/04/x-default-hreflang-for-international-pages

Upvotes: 0

Related Questions