Redirect user to correct domain alias based on browser language detection

Kurt Muller asked on May 30, 2018 12:10

Hi guys

I have seen plenty questions around this topic but none that gives me the solution to my current issue.

Based on this article, I easily understand how to set a specific culture to a URL, but what I want to be able to achieve is have the ability to redirect a user to a specific domain alias assigned to their browsers current language setting.

It's easy enough to just enable "Use language prefix for URLs" under settings but my URLs are as follows:

es.website.com pt.website.com de.website.com

Hope I'm making sense and I'm not missing something obvious.

Correct Answer

Rui Wang answered on May 30, 2018 17:33

If you have configured the language specific sub domains in the sites application, you can handle the redirect by add ?lang=XXXX to the current URL and redirect to that.

For example, someone used pt.website.com but you detected their browser language setting is Spanish, then you can do a redirect using "current URL" + ?lang=es-es, it will be redirected to es.website.com.

1 votesVote for this answer Unmark Correct answer

Recent Answers


Kurt Muller answered on June 1, 2018 09:51

Hi Rui

Your suggestion is easy enough, but I do not want to redirect them to ?lang=.... It has to redirect to the specific subdomain.

Kurt

0 votesVote for this answer Mark as a Correct answer

Rui Wang answered on June 1, 2018 15:30

Hi Kurt, when you redirect them to "current URL" + ?lang=es-es, CMS will be redirected to the subdomain like es.website.com. It's how Kentico handles URL re-write.

0 votesVote for this answer Mark as a Correct answer

Kurt Muller answered on June 5, 2018 09:30

Hi Rui

I don't indend to have any URLs with lang=xxxx assigned to it. The rule is that if they go to www.website.com, it detects your language and redirects you to es.website.com, without the need for lang=es-es

Kurt

0 votesVote for this answer Mark as a Correct answer

Kurt Muller answered on June 13, 2018 14:19

Hi Rui

I double checked configuration and your suggestion is 100% correct! Thank you very much for this. The only thing I've now run into is redirect to a language subdomain, where the exact culture doesn't exist: Browser = es-mx, but I have a culture setup for es-es and needs to point to that domain alias.

But that's for another day :)

0 votesVote for this answer Mark as a Correct answer

Rui Wang answered on June 13, 2018 14:25

That's always the challenge, natural languages vs culture codes, you will either have to replicated Spanish content for all es-XX culture code, or you will have to create a mapping to set all es-XX to redirect to es-es. (BTW, to the local, es-es and es-mx has lots of differences like spelling and wording, similar to en-us and en-gb)

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.