Chapter 6

Using Multiple Domains within Your Network

IN THIS CHAPTER

Check Discovering domain mapping

Check Understanding how to map domains

Check Advanced usage

With a network of multiple sites easily available in WordPress, many people prefer to run multiple sites on their own separate domain names through one install.

In this chapter, I discuss using multiple domains and a feature called domain mapping, which enables you to not only run multiple sites but also multiple sites with unique domain names that aren’t tied to the main site’s installation domain.

To tackle this chapter, you need to understand domains (Book 5, Chapter 1) and Domain Name System (DNS) records.

Finding Your Way with Domain Mapping

Domain mapping means telling your web server which domains you want WordPress to answer to and which site you want to be shown to visitors when they request that domain. This process is more than domain forwarding or masking because the URLs for your posts have the full domain name in them. Instead of the child site’s being in secondsite.yourdomain.com format, it can be in myotherdomain.com.

Domain mapping isn't possible in certain cases, however. If your WordPress install is in a subfolder, and this folder is part of the URL, any mapped domain will also contain this folder name. In that case, it would be better to move the install so that it isn’t in a subfolder.

You also need to access your web host’s control panel (where you manage DNS records on your web server) and the control panel for your domain-name registrar, which is often a different company.

Remember By default, the network install lets you choose between a subdirectory setup and a subdomain setup. This step is still required before you can specify a domain for that site. I cover how to enable the network in Book 8, Chapter 2. Be sure to set up the network and make sure that it’s functioning properly before you attempt to map domains.

Domain aliases

You need to set up your web server to accept any incoming requests for the domain you want to map and the location to send your site visitors to. I use the cPanel control panel (Book 2, Chapter 2) in this section because it’s quite popular and available on many web hosts. On cPanel-based web hosts, this task is referred to as domain parking.

Follow these steps to park a domain on your web hosting account via cPanel:

  1. Log in to your website’s cPanel.

    The address is provided by your web host and usually is available at http://yourdomain.com/cpanel.

  2. In the Domains section, click the Aliases icon, as shown in Figure 6-1.

    The Aliases page displays in your browser window. It lists any domains you've created aliases for (if any) and provides a form for entering a new domain.

  3. In the Create a New Alias section, enter the domain name you want to map in the Domain text box.

    The domain is directed to the root folder of your website, which is where your WordPress install should be located. If it isn’t, follow the next set of steps.

  4. Click the Add Domain button.

    The screen refreshes and shows the domain you added in the Domains lists, shown at the bottom of the page in Figure 6-2,which indicates the successful creation of a domain alias that you entered in step 3.

Screenshot displaying the Aliases icons of the Domains and Metrics in cPanel.

FIGURE 6-1: The Aliases icon in cPanel.

Screenshot of the Aliases page displaying a domain alias to create a new alias and remove aliases.

FIGURE 6-2: The Aliases page showing a domain alias.

Other web hosts may refer to a domain alias as pointing or mirroring. You may need to ask your web host’s support team which area you need to do this in. You’re using a ServerAlias directive for the mapped domains, telling the web server to send all requests for the mapped domain to the domain where WordPress is installed.

If the domain you’re using for your WordPress network installation is an add-on domain rather than the main domain of the website, you have to follow a slightly different process to park the domain. Because you can’t tell a parked domain to go anywhere other than the root folder, you need to use the Addon Domains feature.

Follow these steps to create an add-on domain in your web-hosting cPanel:

  1. Log in to your website’s cPanel.
  2. In the Domains section, click the Addon Domains icon, as shown in Figure 6-3.

    The Addon Domains page appears.

  3. Enter the new domain name you want to map in the New Domain Name field.

    Warning The other fields, Subdomain/FTP Username and Document Root, get autopopulated by your web server. Don’t alter the information that your web server populates for Subdomain/FTP Username; this field is setting the username you’ll use to connect when you need to use SFTP. These settings are defaults for Addon Domains, and you shouldn’t alter them.

  4. In the Document Root field, enter the folder location of your WordPress network installation.

    Figure 6-4 shows the Create an Addon Domain information filled in.

  5. Click Add Domain to save your changes.

    The Addon Domains page refreshes, and your new domain appears in the Addon Domains section.

Screenshot of the Domains section displaying the Addon Domains icon in cPanel.

FIGURE 6-3: The Addon Domains icon in cPanel.

Screenshot of the Addon Domains page to create an Addon Domain information in cPanel or modify an Addon Domain.

FIGURE 6-4: The Create an Addon Domain information in cPanel.

Editing DNS records

To instruct the domain name registrar where to send the domain name to, you need to edit the DNS records. GoDaddy is a common domain-name registrar, I use its domain-registration account interface in the following steps. To edit the name server records, follow these steps:

  1. Log in to your domain-name registrar.
  2. Click the DNS management tools.

    Figure 6-5 shows the information for the domain to map.

  3. Click the Set Nameservers link in the Nameservers section.
  4. Type the name servers for your web host where your WordPress installation.
  5. Click the Save Changes button.

    Now servers around the world know that your domain “lives” at this web server location. Name server changes may take up to 24 hours to propagate across the Internet.

Screenshot of the Domain Manager screen displaying the  domain name records of a mapped domain.

FIGURE 6-5: The domain name records of a mapped domain.

Installing the Domain Mapping Plugin

Before you can add your mapped domains to WordPress, you need to install the WordPress MU Domain Mapping plugin to help handle this task. The Domain Mapping plugin doesn’t do any setup on the server side; it helps you rename the site and takes care of any login issues. To use it, follow these steps:

  1. Click the Plugins link on the Network Admin menu.

    The Plugins screen appears.

  2. Click Add New.

    The Add Plugin screen appears.

  3. Search for WordPress MU Domain Mapping in the search field.

    A list of plugins appears.

  4. Find the plugin titled WordPress MU Domain Mapping by Donncha O Caoimh, and click its Install Now button to install it.
  5. Click the Network Activate button.

    This step activates the plugin for use across your entire network.

  6. Open your SFTP program, and navigate to the wp-content/plugins/wordpress-mu-domain-mapping folder.
  7. Download the sunrise.php file to your computer.
  8. In your SFTP program, navigate to the /wp-content/ folder.
  9. Upload the sunrise.php file to the /wp-content folder. (See Figure 6-6.)
  10. Download a copy of your wp-config.php file by using your SFTP program.

    You can find the wp-config.php file in the main directory of your WordPress installation.

  11. Open wp-config.php on your computer with a text editor, and add the following line below the define( 'MULTISITE', true ); line:

    define( 'SUNRISE', 'on' );

  12. Save the file, and upload it to your website.

    The plugin is available (and running) on your network immediately.

Screenshot of the FileZilla page displaying the /wp-content/plugins folder that contains the sunrise.php file.

FIGURE 6-6: A look at the /wp-content/plugins folder that contains the sunrise.php file.

All you need to do now is set up the options and map a domain to a site. Two new items are added to the Network Settings menu: Domain Mapping and Domains. On the site administrator Dashboard, a new Domain Mapping item appears on the Tools menu.

Remember The network admin needs to activate domain mapping on the Domain Mapping page (choose Network Admin⇒  Settings ⇒  Domain Mapping) before a user can map a domain by enabling the Domain Mapping feature.

Obtaining your IP address

An IP address is a number assigned to every website and computer that's connected to the Internet. This number is used in domain mapping to \direct Internet traffic to the appropriate site in your network. You can find the IP address of your website in three ways: Your web host provider can tell you, the address may appear within the web host’s control panel, and you can visit an IP-lookup website (which can tell you the IP of your website when you provide your domain name). You need the IP address of the domain you want to map in order to complete the domain mapping process. To find your address with an IP-lookup website, follow these steps:

  1. Visit Domaintools’ Reverse IP Lookup website at http://reverseip.domaintools.com.
  2. Enter the domain name of your website and then click the Lookup button.
  3. Write down the IP address displayed.

    Figure 6-7 displays the IP address of Google.com (172.217.3.164).

  4. In your WordPress Dashboard, choose Network Admin⇒  Settings⇒  Domain Mapping.
  5. Enter your IP address in the Server IP Address field.
  6. Click Save.
Screenshot of the Reverse IP record revealing the IP address of Google.com and the results of more than 3 domains hosted on the IP address.

FIGURE 6-7: Reverse IP record revealing the IP address of Google.com.

Mapping a domain to a site

To map a domain to a site in your network, here’s what you need to do:

  1. Navigate to the site within your network to which you want to map a domain.
  2. Log in to that site’s Dashboard.
  3. Click the Domain Mapping link on the Tools menu.

    The Domain Mapping screen appears.

  4. Enter the domain name you want to map to this site.

    The check box indicates whether the domain is the primary domain for this site and is used only if you want to map multiple domains to the site. Only one domain can be the primary domain and used in the URL. Any other domains mapped to this site redirect to the primary domain.

  5. Click the Add button to save your changes.

    The site appears when you enter the mapped domain URL in your web browser’s address bar.

This plugin also lets you map a domain to a site without visiting the site’s Dashboard by choosing Network Admin⇒  Settings⇒  Domains. (See Figure 6-8.) Note: You need to know the unique ID number of the site you want to map.

Screenshot displaying the Domain Mapping: Domains screen maps domains obtained from a single location.

FIGURE 6-8: The Domain Mapping: Domains screen maps domains from a single location.

Mapping a Large Volume of Domains

For some enterprises, you may need to map a large volume of domains (10 or more) to the WordPress network. Adding each domain to the server with a ServerAlias directive is time-consuming. Also, as the list grows, the server slows while reading all the domains.

The time necessary to add these domains can be shortened considerably by using a wildcard host. To use a wildcard host, you need to access your website via a terminal or via Secure Shell (SSH) with the ability to log in with root user capabilities. The ability to add a wildcard is available only on virtual private servers or dedicated hosts. The ideal situation for using a wildcard host is when the main installation of WordPress is the default domain on the server. A quick way to check whether your WordPress main installation domain is the default domain on your web server is to type your IP address in your browser's address bar. If your main WordPress site displays in your browser, you can proceed with using a wildcard host. If not, you need to obtain a dedicated IP address from your web hosting provider.

Configuring Apache

Adding a wildcard host to your web server requires that you access the Apache configuration files on your web server. This section assumes that you have access to those files, as well as SSH login access to your web server. If not, ask your web hosting provider to provide you the access you need or to complete the steps for you.

Here’s how you set up this feature:

  1. Log in to your website as the root user via a terminal.
  2. Navigate to the configuration files in the folder located at /etc/httpd/ by typing

    cd /etc/httpd/

  3. Open the httpd.conf file by typing

    vi httpd.conf

    Page down in the file until you see the vhost section. Find the that contains information about your WordPress installation and the main domain of your network. (Depending on the number of domains hosted on your server, you may find several vhost entries in the httpd.conf file; be sure that you're editing the vhost that contains the main domain of your WordPress install.)

  4. Press the Insert key to begin editing the file.
  5. Comment out the lines and place the wildcard as follows:

    <VirtualHost *:80>

  6. Save the changes by pressing the Esc key, typing :wq, and then pressing Enter (or Return on a Mac).
  7. On the command line, restart Apache by typing

    /etc/init.d/apache restart

Now you can map domains in volume by following these steps:

  1. Log in to your domain-name registrar.
  2. Click the domain-name management tools for the domain you want to map.
  3. Click the DNS records.

    (Refer to Figure 6-5 earlier in this chapter.)

  4. Locate the A records at the top of the page, and insert the IP address of your WordPress network.

    (I show you how to obtain this address in “Obtaining your IP address” earlier in this chapter.)

    Figure 6-9 shows an A record and the web-server IP address to which it points. The domain is sent to that IP address regardless of name server.

  5. Choose Network Admin⇒  Settings⇒  Domains from your WordPress Dashboard.

    The Domain Mapping: Domains page appears, as shown in Figure 6-10.

  6. Enter the ID of the site you want to map.

    You can get the ID number from the Sites page (by choosing Network Admin⇒  Sites). I used site ID 2 in Figure 6-10.

  7. Enter the domain name you want to map to this site.

    In Figure 6-10, I used myamazingdomain.com as the domain name I want to use for the site.

  8. Click Save.

    The page refreshes and shows you a list of mapped domains.

Screenshot of the Domain Manager screen displaying the list of Domain A records.

FIGURE 6-9: Domain A records.

Screenshot of the Sites page for mapping a domain from the Domain Mapping: Domains page.

FIGURE 6-10: Mapping a domain from the Domain Mapping: Domains page.

You no longer need to park or point domains at the web host. If you added the wildcard host in your Apache configuration, the server is instructed to take any domain-name request and send it to the WordPress network, based on the IP that you added. WordPress associates the mapped domain with the correct site.

Hiding the original installation domain

The WordPress MU Domain Mapping plugin, mentioned in “Installing the Domain Mapping Plugin” earlier in this chapter, lets you access the child site by the original location regardless of whether it’s a subdomain or subfolder site. As a result, you can use domain mapping no matter which setup you chose for your network (subdomains or subdirectories). The domain mapped for the child site is also the domain used on all uploaded media files, thereby maintaining consistency for the site.

In some cases, you may want to hide the original installation domain. If your main installation domain is an obscure-looking domain like http://00954-yourvpsdomain-ba.com, for example, you want to hide that domain because your site visitors can't easily remember or use it. If you want to hide the original installation domain, here’s how you can do so:

  1. Choose Network Admin⇒  Sites.

    The Edit Site screen appears in your Network Admin Dashboard.

  2. Hover your mouse pointer over the name of the site you want to edit, and click the Edit link that appears, as shown in Figure 6-11.

    The Edit Site screen appears in your browser window.

  3. Click the Settings tab of the Edit Site screen.

    This tab displays various settings for the site you’re editing. (See Figure 6-12.)

  4. Find all instances of the original domain name, and change them to the new mapped domain.

    Be sure to click each tab on the Edit Site screen (Info, Users, Themes, and Settings) to change the original domain name to the new mapped domain wherever it appears on the Edit Site screen. Keep any folder names intact.

  5. Save your changes by clicking the Save Changes button.
Screenshot displaying the Edit Site screen providing the link for individual sites.

FIGURE 6-11: The Edit link for individual sites.

Screenshot displaying the Edit Site page of the Network Admin Dashboard to be filled in by the user.

FIGURE 6-12: The Edit Site page of the Network Admin Dashboard.

Now your mapped site is inaccessible at the original child-site domain, and any references to it have been changed. Previous links within the body of posts, however, aren’t updated automatically, so you need to edit the posts manually to change the links to reflect your newly mapped domain.

Setting Up Multiple Networks

Multiple networks are supported in the WordPress code base, but there’s no built-in menu or interface on the Dashboard. Running multiple networks in one install is an advanced feature that allows you to have another network in the same installation acting as a second independent network of sites. That network can use its fully qualified domain name or a subdomain. The extra networks inherit the same type of sites. If your original network was installed with subdomain sites, the extra network will also have subdomain sites. The network admin carries over to the new network, too. Additionally, you can add other network admins to the second network without giving them network-admin access on the original network.

The plugin that helps you perform this task is WP Multi Network (available at https://wordpress.org/plugins/wp-multi-network). You install and manage the WP Multi Network plugin in a way that’s similar to how you install and manage the WordPress MU Domain Mapping plugin. The domain for the new network still needs to be parked on the install, but the creation of the network is done on the Add New Network screen after you install the WP Multi Network plugin. You can’t turn an existing site on the network into a second network; you must set up a new site when the new network is created. Figure 6-13 shows the

Screenshot displaying the Add New Network screen in the Network Admin Dashboard to be filled in by the user.

FIGURE 6-13: The Add New Network screen in the Network Admin Dashboard.

When this plugin is installed and the network is activated, you see a new menu on the Network Dashboard: called Networks. Click the Add New link on the Networks menu to load the Add New Networks screen.

To create a new network, fill in the fields on the Add New Networks screen:

  • Network Title: The name of the network you’re creating (such as My New Network)
  • Details: The settings for the Domain and Path
  • Domain: The domain name you’ll use for this new network (such as mynewnetwork.com)
  • Path: The server path your new network will use (such as /home/mynewnetwork/public_html/)
  • Root Site: The settings for the Site Name
  • Site Name: The name of the site that will serve as the main site of this network (such as Network Main Site)

When you’re done, click the Create button on the right side of the Add New Network screen. WordPress creates your new network, and you can assign child sites to it.