Learn how to use Domain Access module in 10 easy steps

Submitted by hemant.gupta on Mon, 05/16/2016 - 09:51

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

NameVirtualHost *:80


ServerAdmin webmaster@example.com
ServerName delhi.example.com
ServerAlias www.delhi.example.com
DocumentRoot /srv/www/example.com/public_html/
ErrorLog /srv/www/example.com/logs/error.log
CustomLog /srv/www/example.com/logs/access.log combined

AllowOverride All
Order allow,deny
Allow from all


ServerAdmin webmaster@example.com
ServerName mumbai.example.com
ServerAlias www.mumbai.example.com
DocumentRoot /srv/www/example.com/public_html/
ErrorLog /srv/www/example.com/logs/error.log
CustomLog /srv/www/example.com/logs/access.log combined

AllowOverride All
Order allow,deny
Allow from all


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.


/**
* Add the domain module setup routine.
*/
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.