question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add self-referencing canonical to language routes

See original GitHub issue

Background: 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:closed
  • Created 3 years ago
  • Comments:15

github_iconTop GitHub Comments

1reaction
rchlcommented, Oct 14, 2020

To resolve my particular case, I generate website with defaultLocale: '', and then cp -a ./dist/en/. ./dist. Not perfect, and doesn’t generate x-default, but it works.

Wouldn’t prefix strategy + defaultLocale: 'en' give you the x-default? Then you can use your copy hack with that.

1reaction
rchlcommented, Oct 13, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add self-referencing canonical to language routes #918 - GitHub
Background: As mentioned in #915 , I am working on making i18n module work with i18n rewrites. Basically, this allows to serve user...
Read more >
Canonical Tags: A Simple Guide for Beginners - Ahrefs
Canonical tags help to combat duplicate content issues. They tell search engines like Google to index and rank the right pages.
Read more >
Correct Hreflang & Canonical Implementation for Multilingual ...
1 - Self-Referencing Hreflang Tag Necessary? The first is regarding the correct implementation of hreflang, and whether or not I should have a...
Read more >
Rel=Canonical URL Tag Guide & SEO Best Practices
A canonical tag can be self-referencing — meaning that it points to its own URL — or it can point to another page's...
Read more >
What is the best way to generate a self-referencing canonical ...
I am just trying to verify the best way to add a self-referening canonical tag to a multilingual Sitecore site ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found