Search code examples
drupal-7multisite

Access base URL of main site in another site in Drupal 7


I have setup multisite in Drupal 7 and need to access theme settings and base url (test.com) of a main site in test1.test.com. How Can I do this one?

For example:

Main site: test.com<br>
Multisite: test1.test.com<br>
Multisite: test2.test.com <br>

likewise.

Folder structure:

sites/all/themes/testtheme/<br>
sites/test1/themes/custom_theme/test1<br>
sites/test2/themes/custom_theme/test2<br>

Thank you in advance.


Solution

  • I assume you should be using a different settings.php with a different DB for each sub-domain site, and in this case you can't access the variables of other sites into another site. However, there are two ways to get the main site base_url in other sites.

    First, you could add a configurations variable through settings.php like $conf['main_site_base_url'] in individual settings.php OR the other way, if you are using a shared codebase, you can set this variable in custom module hook_init() or hook_boot() [whichever works with your setup] with this variable_get('main_site_base_url','test.com').

    Once the confiuration variable set into the system you could get this using the variable_get function like variable_get('main_site_base_url','').

    For inheriting the theme settings I would suggest to go with a sub-theme option as explained in this post.