Server setting for languages in different domainsJanuary 16th, 2011 by Amir
WPML can serve different languages from different domains or sub-domains. For this to work, some setup is required in your web server. We’ll start with the theory of how it works, so that you understand how to set it up on your own server.
When a request comes in, this is what happens:
- The DNS tells the browser where the site is hosted.
- The web server gets the request and decides which virtual host answers.
- The virtual host runs WordPress and WPML. WPML tells WordPress which page to return for each language.
For languages in different domains to work, all languages need to point to the same WordPress installation. You need to set the DNS and Apache configuration to do this.
If you find yourself editing .htaccess, trying to redirect requests from one domain to the other, you’re doing something wrong. There’s only one WordPress install, so there’s nothing to redirect to.
1) Set up the DNS
You need to register all domains or sub-domains for different languages. How you do this greatly depends on your hosting control panel, but the end result is always the same. All domains must go to the same web server.
If you’re running a local site (localhost) and want to test this configuration, you’ll need to edit the ‘hosts’ file and add the entries for the different domains.
Normally, the local server address is 127.0.0.1, so if you want to test domains such as es.local and de.local, add this to your existing hosts file:
127.0.0.1 es.local 127.0.0.1 de.local
On Linux PCs, the hosts file is in /etc/hosts. In Windows, it’s normally in C:\WINDOWS\system32\drivers\etc\hosts.
2) Set up the web server
In our example we’re going to use Apache and explain how the configuration files look. You server might have a control panel on top of Apache which adds nice graphical control to the Apache configuration files. If you can’t determine how to implement the following using the control panel, you can copy the example from here and ask your hosting provider.
The easiest way is to have a single VirtualHost entry for all domains and use ServerAlias instructions to tell Apache to answer the different domains with the same virtual host.
<VirtualHost *> DocumentRoot /your_wp_install_directory/wordpress ServerName www.english-domain.com ServerAlias www.french-domain.fr ... your other stuff here ... </VirtualHost>
This tells Apache that there’s a single WordPress install which answers to requests from www.english-domain.com and www.french-domain.fr. It doesn’t matter of those are completely different domains or sub-domains.
If you don’t know how to set up ServerAlias in the virtual host file (maybe because you don’t have any direct access to it), you can set up two VirtualHost sections, both pointing to the exact same DocumentRoot (the path to where WordPress is installed), but with different ServerName values.
You can test this setup even without WPML (recommended). Go to both domains and see that you see your WordPress site.
Note: Many shared hosting providers will not allow you to directly edit Apache’s configuration file. Instead you can try to create cPanel-addon domains that point to the same physical WordPress installation.
3) Tell WPML you’re using different languages in domains
Once this setup is working, you can tell WPML to use it to determine languages.
Go to WPML->Languages. There, choose languages ‘A different domain per language‘. WPML will ask you for the domains of each language. Enter, validate and save.
The default values which WPML sets in the language fields are sub-domains with the locale names. You can overwrite it with your actual domain names.
This FAQ describes the required steps to setup languages in domains for a single-site WordPress install.
You can use languages in domains in multisite mode, following additional configuration. To do this, follow the guide for setting up languages in domains in multisite mode.