Add self-referencing canonical to language routes
See original GitHub issueBackground: As mentioned in #915 , I am working on making i18n module work with i18n rewrites. Basically, this allows to serve user content from CDN in their language, without a redirect.
The functional part is resolved, but there is an issue with SEO, which doesn’t do what is desired in URL rewrite case.
Currently, with prefix_and_default
strategy and seo
enabled, the rel=canonical tag will be added on default language routes. This means, that when default language is “en”,
/ <- this one is canonical
/en <- this one will have link rel=canonical href="/"
This is great and exactly how it should work without rewrites. With rewrites, however, the desired behavior would be reversed: the canonical tag should point to language route, not the default:
/ <-default route never canonical, but have link rel=canonical href="/{{defaultLocale}}"
/en <- should have self-referencing link rel=canonical href="/en"
/fr <- should have self-referencing link rel=canonical href="/fr"
Additionally, the default route should have hreflang="x-default"
, signaling that no other language/region matches the user’s browser setting.
With this setup, we can expect the crawler to scan all language routes, but not the default routes, because the content of default routes depends users’ browser settings and should not be indexed.
What is the best way to introduce such change? Any guidance would be appreciated.
Here is what I am thinking regarding config changes:
Current behavior (marks default route as canonical)
i18n: {
seo: true
// or
seo: {
defaultCanonical: true
}
}
Desired behavior for i18n rewrites (marks language routes as canonical, plus sets hreflang="x-default"
for default route)
i18n: {
seo: {
defaultCanonical: false
}
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:15
Top GitHub Comments
Wouldn’t
prefix
strategy +defaultLocale: 'en'
give you thex-default
? Then you can use your copy hack with that.Fixed for #912 are released in https://github.com/nuxt-community/i18n-module/releases/tag/v6.15.2 but not sure if it’s not gonna fully help your case.