You are here

Learn how to use Domain Access module in 10 easy steps

There are times when you want to make want to make a site which when access through a particular place will show particular content or specifically speaking when accessed from different domains will show different content.so in this blog i am going to tell you about the domain module which can be used to show different content to the user according to the URL referred.
Before reading I would recommend to read this.
Here are the steps

1. Install Drupal as you do normally

2. Create the required sub domains that you want and point them all to the same Drupal root
delhi.example.com (Primary site)
mumbai.example.com

Add the following in your /etc/httpd/conf.d/vhost.conf file

  1. NameVirtualHost *:80
  2.  
  3. <VirtualHost *:80>
  4. ServerAdmin webmaster@example.com
  5. ServerName delhi.example.com
  6. ServerAlias www.delhi.example.com
  7. DocumentRoot /srv/www/example.com/public_html/
  8. ErrorLog /srv/www/example.com/logs/error.log
  9. CustomLog /srv/www/example.com/logs/access.log combined
  10. <Directory /srv/www/abc/public_html/>
  11. AllowOverride All
  12. Order allow,deny
  13. Allow from all
  14. </Directory>
  15. </VirtualHost>
  16.  
  17. <VirtualHost *:80>
  18. ServerAdmin webmaster@example.com
  19. ServerName mumbai.example.com
  20. ServerAlias www.mumbai.example.com
  21. DocumentRoot /srv/www/example.com/public_html/
  22. ErrorLog /srv/www/example.com/logs/error.log
  23. CustomLog /srv/www/example.com/logs/access.log combined
  24. <Directory /srv/www/abc/public_html/>
  25. AllowOverride All
  26. Order allow,deny
  27. Allow from all
  28. </Directory>
  29. </VirtualHost>

3. Make sure that these domains open up in the browser and your website is accessible by all these domains.

4. Install the domain module

5. Before you enable the module add the following lines in settings.php file.

  1. /**
  2. * Add the domain module setup routine.
  3. */
  4. include DRUPAL_ROOT . '/sites/all/modules/domain/settings.inc';

6. Now enable the module and go to: Administration > Structure > Domains to make sure there are no error messages

7. Go to admin/reports/status/rebuild to Rebuild the permissions.

8. Your first domain will become default domain and all existing nodes will be assigned to your primary domain.

9. Now go to Administration > Structure > Domains to create one more domain mumbai.example.com using same settings as primary domain. At this point if you create a new user and assign it to mumbai.example.com then that user created node will be assigned to mumbai domain

10. If you want each domain to have their own moderator i.e. role who will edit all the nodes of a particular content type then change the permissions as mentioned below.
Go to :Administration > People > Permissions >Roles and select edit permissions for moderator role

Under Domain Access
Check this permission: "Client: Edit any content on assigned domains" (do for all content types)

Under Node
Uncheck this permission: "Client: Edit any content"

Using the permissions so far user of any domain/affiliate can view all the nodes across all the domains.

And that is it.

How to show the nodes of a particular affiliate separately in the view.

1. Install Domain views module

2. Add the field "Domain ID" in the view, the same field can be added as a filter and exposed to the user to change.