How To Create A Multilanguage Solution With i18n And Subdomains In 7 Easy Steps

One option for making a multilanguage site in Drupal is to use subdomains rather than directories or separate root domains. All these three options have pros and cons SEO-wise as is explained by this excellent article, but there are of course more things to consider than a site's SEO rating. For example, SSO is extremely difficult to achieve in a satisfying way when you use different root domains due to cookie-related limitations. Achieving this using subdomains is really a lot easier so that's what I'm going to focus on in this post.

Let's say you wish to create a multilanguage site with SSO and synchronized files/images for certain node types. We're going to assume that you already have a functioning multilanguage site using folders, which is the very easiest option for developers. We're also going to assume that the hosting company you use for this site doesn't allow symlinks. Finally we're going to avoid using any extra third-party modules. One way to convert this site into a subdomain solution with these conditions is to follow these steps:

1. Create the subdomains you want to use, naturally.
2. Select one of the domains as a "master" domain where the files will be stored and move your site into the directory that the domain is pointed to.
3. Enter the language negotiations settings (admin/settings/language/configure/language) and select "Domain name only".
4. Enter the "edit" page for each language, remove the path prefix and type the domain you wish to use, for example "". For the default language, type the domain that is pointed to the directory in step 2.
5. Open up settings.php and insert this code:

$domain = $_SERVER['HTTP_HOST'];
$levels = substr_count($domain, '.');
if($levels>1) {
$count = 0;
for($i=0, $imax=strlen($domain); $i<$imax; $i++) {
  if(substr($domain, $i, 1)=='.') {
   if($count==$levels-1) {
    $domain = substr($domain, $i+1);
$cookie_domain = '.'.$domain;

This sets the domain for the cookie to the root domain for your website and adds a dot before it so that it also includes the subdomains. That takes care of the SSO.

6. In settings.php, also insert this code:

$conf['file_downloads'] = 2; //1 = Public downloads, 2 = Private downloads
$docpath = explode('/',$_SERVER["DOCUMENT_ROOT"]);
$docpath = implode('/', $docpath);
$conf['file_directory_path'] = $docpath.'/'.'';

Exchange "" for the name of the directory to which the master domain is pointed. This snippet sets the download method to private and sets a path for the files directory.

7. That's it! All you need to do now is to copy the full directory of the master domain to the directories where the other subdomains are pointed and it should work. You don't need to make any configuration changes as all are supposed to be the same as for the master site.