jumph4x/canonical-rails

Exclude default language from canonical URL

Closed this issue · 2 comments

My website supports multiple languages, for example:

https://www.example.com/mypage
https://www.example.com/en-US/mypage
https://www.example.com/fr-FR/mypage

https://www.example.com/mypage and https://www.example.com/en-US/mypage are actually the same page because en-US is my default language.
What would be the best option to remove /en-US from canonical URLs ? I can write a PR if necessary.

This is an interesting problem.

I would recommend writing a method that the default locale using the I18n module as per https://guides.rubyonrails.org/i18n.html#managing-the-locale-across-requests

We can then perform a check to see if the default locale does not match the current locale, and if that is the case, write logic to serve the default locale.

Due to the complexity of the various use cases of managing locale, I don't think we can craft a meaningful general purpose PR.

I recommend decorating the logic. If I were you, I'd simply build a RegEx match for all supported locales at runtime based on I18n, then do a string sub.

Doesn't sound like there's any movement. Feel free to re-open, but in the current form, I deem this request non-idiomatic.