Drupal7 Use Subdomains With Multilingual Sites

Subdomains with multilingual sites

Make multidomain work in multilingual site

The website we manage uses multilingual features. We have this site in 3 different languages. Language detection is done using URL.

Recently, the requirement came up to make subdomain on this site.

The following is step by step guide to create subdomain and make it work with multi language.

1 - Download module

Download and enable Domain access module and enable it.

You will receive an error  "domain access failed to load during the bootstrap phase".

Subdomains with multilingual sites

You have two options to solve this issue.

Option 1:

Copy following code in your settings.php

 /**
     * Add the domain module setup routine.
     */
    include DRUPAL_ROOT . '/path/to/modules/domain/settings.inc';

Make sure to replace "/path/to/modules/" to directory in which domain module is present. Normally it is "sites/all/modules".

Option 2:

If you are having difficulty determining the correct path, copy the following files into your settings folder.

domain > domain.bootstrap.inc
domain > settings.inc
domain > settings_custom_url.inc
The files should be in the same directory as your active settings.php file.

Then add the following lines:

/**
 * Add the custom_url_rewrite_outbound function.
 */
include 'settings.inc';

More details available here or you can hire drupal developer for help.

2 - Add domain

Navigate to "admin/structure/domain/create" and create domain.

Subdomains with multilingual sites

3 - Configure domain

To have domain specific configurations, you need to have Domain Configuration and Domain Settings sub modules enabled. Enabling this module allows you to have different settings on each domain. These settings include domain email address, site slogan, front page, menu settings etc.

Subdomains with multilingual sites

4 - Theme setting for domain (optional)

If you want your subdomain to have separate theme, you need to enable Domain Theme submodule. This module allows you to set theme for subdomain.

Subdomains with multilingual sites

5 - Set multi language for domain

Imagine a scenario where we have multilingual sites with domains de.example.com and en.example.com. Now, we want to create subdomains for this site. These subdomains will have URL like this: test.de.example.com and test.en.example.com.

Both de.example.com and test.de.example.com are in german language. Similarly, both en.test.com and test.en.example.com are in english language.

To implement this, we need to use Language MultiDomain module. Along with this module we need to use patch from here to make this work properly.

Once this module is enabled, navigate to "admin/config/regional/language" and edit language and set multiple domains in "Language Domain"

Subdomains with multilingual sites

Save and you are done. Now you have 4 domains.
 

That's so easy now :) Feel free to catch more quick solution blogs and your feedbacks would be very valuable.