Click here to Skip to main content
15,879,474 members
Articles / Drupal

Working With Domain Access Module in Drupal 7.x

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
24 Oct 2014CPOL9 min read 15.9K   1   2
Installation steps: 1. Download and install the Domain Access module using this link. 2. Then paste the following in your settings.php file : 3. Then rebuild the permission. Domain Access: i. Enable “Domain Access” in the modules section. ii.

working-with-domain-access-module

Installation steps

  1. Download and install the Domain Access module using this link.
  2. Then paste the following in your settings.php file:
/**
 * Add the domain module setup routine.
 */
include DRUPAL_ROOT . '/sites/all/modules/domain/settings.inc';
  1. Then rebuild the permission.

Domain Access

  1. Enable “Domain Access” in the modules section.

    38

  2. Navigate to “Admin->Structure->Domains”.
  3. There will be multiple tabs, but for now we will navigate to the “Domain List” tab. There we will find “localhost” as the only domain listed.

    1

  4. There we will find an option labelled as “Create Domain”. Then we click on that link to create a new domain with the “Domain” value as “testdomain1.com” and “Name” value as “test domain1″ and then we leave all other fields as it is and then we click on “Save Domain Record” button.

    2

  5. After saving the new domain record we will see a domain with the name “test domain1″ appears in the “Domain List”.

    3

  6. Navigate to the windows “hosts” file located at “Windows/system32/drivers/etc/hosts” and then define an alias as “127.0.0.1 testdomain1.com” and then we restart the server.
  7. Now we navigate to our “Domain List” and there we will notice that the active domain is highlighted. For now we see that “localhost” is highlighted.

    4

  8. Now we open http://testdomain1.com/<your-drupal-installation-directory&gt; in a separate window. After that we login as administrator and then we navigate to “Domian List”, there we would see that “test domain1″ is highlighted.

    5

  9. Then we proceed to create a node of basic page content type. When we create a node, we will get an option as “Domain access options” on the node creation page.

    6

Here we have two options

  1. Send to all affiliates: After checking this option, the content will be published on all domains.
  2. Publish To: Here we will have all the domain names listed. We can select the domain, where we want this node to be published.

Note: We need to avoid selecting “Send to all affiliates” option if we need to publish a node to particular domains. But the nodes will be shown to the administrator, even when logged in from a domain in which a node is restricted.

We had created a node named as “Test basic page 1″, and then we had set “localhost” in the “Publish To” section and we had unchecked “Send to all affiliates”, as a result the page is not shown up on “testdomain1.com” and it is shown up on “localhost”. When we try to access this page via URL also on “testdomain1.com” we will be redirected to access denied page.

7

8

In the “Domain List” we have an option as “DEFAULT”.

9

We can set our default domain here. Our default domain is the one, which will be used for all requests that fail to resolve to a registered domain.

Domain Alias

  1. Enable “Domain Alias” in the modules section.
  2. Navigate to the windows “hosts” file located at “Windows/system32/drivers/etc/hosts” and then define an alias as “127.0.0.1 testdomain2.com” and then we restart the server.
  3. Then navigate to “Domain List” and edit the domain named as “test domain1″.

    11

  4. Then we will find the “Aliases” tab. Click on that tab.

    12

  5. Then we could find that in the “Registered aliases for testdomain1.com” section there are no aliases recorded for this domain. Then in the “Add new aliases” section we add an alias as “testdomain2.com”.

    13

  6. Now when we open http://testdomain2.com/<your-drupal-installation-directory&gt;, we will notice that we are automatically redirected to “http://testdomain1.com/<your-drupal-installation-directory&gt;. Hence we had successfully created an alias for http://testdomain1.com/<your-drupal-installation-directory&gt;.

Note: We cannot have a domain, present in our “Domain List” in the alias section.

Domain Configuration

  1. Enable “Domain Configuration” in the modules section.
  2. Then navigate to “Domain List” and edit the domain named as “test domain1″.
  3. Then we will find the “SETTINGS” tab. Click on that tab.

    14

  4. In the “SETTINGS” page we have the complete site settings for that particular domain:
  1. Site Configuration

    15

  2. Administrative Theme.

    16

  3. Time zone Settings.

    17

  4. Performance

    18

  5. Maintenance mode

    19

  6. Menu Settings

    20

  7. Content type menu Settings

    21

Domain Content

  1. Enable ‘Domain Content’ in the modules section.
  2. Then in the admin panel we would see a tab labelled as “Affiliated Content” would appear.

    22

  3. The “Affiliated Content” section shows all the affiliate sites, whose content we can edit. We can click on the affiliate site’s link to view the content that has been assigned to it.

    Here we have two site’s that is localhost and testdomain1.com, after clicking on any of which we can see the content that has been assigned to it, and we can also edit the content.

    23

  4. Then we create a node of basic page content type, and in its domain access option, we unchecked “Send to all affiliates”, and in “Publish to” section we only select localhost.

    24

  5. Then go to “Affiliated content” section and we open “localhost” to view the content assigned to it. We could see that “Test Basic Page 1″ is listed.

    25

  6. Then we open “testdomain1.com” to view the content assigned to it. We could see that there is no content listed.

    26

Domain Source

  1. Enable ‘Domain Source’ in the modules section.
  2. After that we create a node of basic page content type. Then on the node creation page we would get an option labelled as “Source Domain”.

    27

  3. In the “Source domain” section we would get a drop down box in which all the domains that we had defined would be listed along with the “Active Domain” option.

    In our case we will have “Active Domain”, “localhost” and “test domain1″ in the drop down list.

  4. When we define a source domain for a node, and then if we open that node from any other domain other than the source domain defined for that node, then we will automatically be redirected to the source domain. If we are logged in as admin from any other domain, other than the source domain defined for that node, and then we edit that node, then we would be redirected to the source domain, and then we would be required to login as admin again, and after that we would be able to edit that node.

    In our case we had defined a node of basic page content type and we gave the source domain for that node as “test domain1″. The we open “localhost” and after that we open the node defined, then we notice that we are automatically redirected to “testdomain1.com”, and then we are able to view that node.

  5. When we select “Active Domain”, then the current domain in which we are working would be used as the source domain.

Domain Strict

  1. Enable ‘Domain Strict’ in the modules section.
  2. Then we create a node of basic page content type, and in its domain access option, we unchecked “Send to all affiliates”, and in “Publish to” section we select both “localhost” and “test domain1″. After doing this the node so defined can be viewed on “testdomain1.com” and “localhost”.
  3. Then we create two users, “testuser1″ and “testuser2″ from the admin side and on the user creation page, in the “Domain Access” section we select “localhost” for testuser1, and “test domain1″ for testuser2.

    Domain access settings for testuser1.

    28

    Domain access settings for testuser2.

    29

    In the “Domain Access” section we select the affiliates to which a user belongs to. This is used to grant editing permissions for users with the “edit domain content” permission.

    The users that we had created can successfully log in on any domain. This should not be misunderstood that, if we had selected “localhost” for testuser1 then he would only be able to login on localhost domain. The “testuser1″ can also login on “testdomain1.com”.

    We can restrict the users to be able to login to only particular domain, which I will discuss later.

  4. After we enable “Domain Strict”, then the node for which “Send to all affiliates” is unchecked, then that node could not be viewed by anonymous users.
  5. “Domain Strict” allows only the registered users to view a node after they login, on the basis of the domain(affiliate selected for the user at the time of user creation) a user belongs to. It forces users to be assigned to a domain in order to view content on a domain.

Here we had created a node which is published to both “localhost” and “test domain1″. And after that we had created two users, “testuser1″ which belongs to “localhost” and “testuser2″ which belongs to “test domain1″.

Now when “testuser1″ logs in on “localhost” then the “testuser1″ would be able to view the that node. And when “testuser2″ logs in on “localhost” then the “testuser2″ wont be able to view that node. And vice-versa happens on “testdomain1.com” for “testuser1″ and “testuser2″.

Domain Theme

  1. Install a theme and just “enable” it. We can find many Drupal responsive themes available for free on this site http://www.devsaran.com/free-drupal-theme.
  2. Enable ‘Domain Theme’ in the modules section.
  3. Then navigate to “Domain List” and edit the domain named as “test domain1″.
  4. Then we will find the “THEME” tab on the domain edit page. Click on that tab.

    30

  5. In the theme page we find that “Bartik” is the default theme selected for “testdomain1.com”.

    31

  6. Since I had installed “Nexus theme”, I select that theme and then set it as domain theme for “testdomain1.com”.

    32

  7. Then we open http://testdomain1.com/<your-drupal-installation-directory&gt;, we will find we will have a different theme for it, and we have “Bartik” for http://localhost/<your-drupal-installation-directory&gt;.

    33

Domain Bonus

  1. Download and install the “Domain Bonus” module from here. Then Enable ‘Domain Bonus’ in the modules section.
  2. Previously we had created two users, “testuser1″ who belonged to “localhost” and “testuser2″ which belonged to “test domain1″ respectively.
  3. The “Domain Bonus” module restricts the users from logging in on any other domain to which they don’t belong.

In our case “testuser1″ is successfully able to login on “localhost”, but “testuser1″ is restricted from logging in on “test domain1″.

Blocks provided by Domain Access module

  1. Domain access server information : Displays the active domain’s server information.

    34

  2. Domain switcher : Provides an interface to switch between domains on a single click. The active domain will be highlighted.

    35

  3. Domain alias switcher : Provides an interface to switch between domains on a single click. The active domain will be highlighted.

    36

  4. Domain list navigator : Provides a drop down interface to switch between domains. The active domain will be selected.

    37

This article was originally posted at http://azharuddinkhanblog.wordpress.com?p=13

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Questiondomain access module Pin
muhammad ayaz20-Sep-17 21:32
muhammad ayaz20-Sep-17 21:32 
domain access module provide me the functionality of publishing article in selected or all domain. is it provide the same functionality in views that i select domain or select all domain when i make the views in drupal 7.
GeneralMy vote of 5 Pin
Darrell Ulm1-Sep-17 4:52
Darrell Ulm1-Sep-17 4:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.