I'm trying to figure out how to switch/redirect to nanother domain based on language in the URL.
I have a site using two domain names domain1.tld and domain2.tld. The site is on wordpress with WPML, and the URLs are formed this way: domain1.tld/en-US/page1 domain2.tld/es-ES/page1
Crappy solution for now: In order to avoid some troubles with search engines, I put in the index.php a script that redirects to the domain associated with a language. But each time I update wordpress, I have to rewrite the file.
How can I associate a domain to a language in Nginx ? I mean, if a visitor lands on domain1.tld/es-ES/page1, he should be redirected to domain2.tld/es-ES/page1.
I need to implement this because of trademarks that are not the same in all countries. So I need to link one or more languages to a domain.
To clarify a bit, the website is divided in languages, ie /fr-CA/pages, /fr-FR/pages, /en-US/pages, /en-CA/pages, /es-ES/pages and so on.
When a visitor arrives on the site, he's redirected by the domain name to a base language. domain1.tld/ redirect by default to domain1.tld/en-US/home, and domain2.tld/ redirect to domain2.tld/fr-CA/acceuil
He's not redirected on his browser lang.
If he decides to change site language, the domain name might change based on the language he choose.
Each language on the site is associated to a domain name. Thus every domain name can be linked to one or more languages.
If a visitor requests domain1,tld, he's redirected to domain1.tld/en-US. If now he wants US spanish from a drop down menu, he's redirected to domain1.tld/es-US/. If he changes again and want it canadian french, he's redirected to domain2.tld/fr-CA/ because fr-CA is linked to domain2.tld
I was looking for something like this:
location ~* /(es-ES|fr-FR/fr-CA)/ {
# if user is on domain1.tld, redirect to domain2.tld
}
location ~* /(es-US|en-CA|en-US)/ {
# if user is on domain2.tld, redirect to domain1.tld
}
I'd like to detect the language in the URL path and redirect to the domain linked to the language.
I know it's a bit complicated, but that's marketing things and I can't avoid it.
Thanks.