I have:

  • 2 domains
  • single database
  • Single codebase
  • single form with a text-editor and submit button.

What I want is the recognition of domain at database level. So, let's say if I hit http://example.com/en it should save in db with table T1 and if I hit http://example.fr/en it should also save in same db but with different table T2.

And now when I will fetch default value from table T1, it should only reflect to http://example.com/en and similarly for T2 it goes here - http://example.fr/en.

But because of same database and code base of both domains it is difficult to know from which domain the request is coming.

I have 1 solution is like create a table in .install file by considering global $base_url; and then check if table name = $base_url.my_table exists, fetch all results.But I'm not sure it's the best approach in Drupal 8 or some other way to achieve this.

Please share best approach for this.

1 Answer 1


You need to enable multisite.

The documentation inside the settings.php file is also very helpful, read that too by viewing the source of the file here https://api.drupal.org/api/drupal/sites!default!default.settings.php/8.

Briefly, the steps are,

  1. Multi-site requires the existence of the sites/sites.php file in your Drupal 8 installation. You will need to create this file manually.

Example content would be:

$sites['mysite.com'] = 'site1';
$sites['8000.localhost'] = 'site2';
  1. Create a site directory inside sites/, the path should be sites/site1. Put a settings.php file in this directory in order for Drupal 8 to recognize it.

  2. Visit the URL of site1, like mysite.com to install it.

  • This question was tagged with 8. Meaning it's for Drupal 8 not 7.
    – No Sssweat
    Sep 9, 2016 at 8:14
  • 1
    I have updated my answer to reflect Drupal8 instead of Drupal7
    – Cninroh
    Sep 9, 2016 at 8:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.