Chapter 6
IN THIS CHAPTER
Discovering domain mapping
Understanding how to map domains
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.
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.
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:
Log in to your website’s cPanel.
The address is provided by your web host and usually is available at http://
yourdomain.com
/cpanel
.
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.
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.
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.
FIGURE 6-1: The Aliases icon in cPanel.
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:
In the Domains section, click the Addon Domains icon, as shown in Figure 6-3.
The Addon Domains page appears.
Enter the new domain name you want to map in the New Domain Name field.
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.
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.
Click Add Domain to save your changes.
The Addon Domains page refreshes, and your new domain appears in the Addon Domains section.
FIGURE 6-3: The Addon Domains icon in cPanel.
FIGURE 6-4: The Create an Addon Domain information in cPanel.
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:
Click the DNS management tools.
Figure 6-5 shows the information for the domain to map.
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.
FIGURE 6-5: The domain name records of a mapped domain.
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:
Click the Plugins link on the Network Admin menu.
The Plugins screen appears.
Click Add New.
The Add Plugin screen appears.
Search for WordPress MU Domain Mapping in the search field.
A list of plugins appears.
Click the Network Activate button.
This step activates the plugin for use across your entire network.
wp-content/plugins/wordpress-mu-domain-mapping
folder.sunrise.php
file to your computer./wp-content/
folder.sunrise.php
file to the /wp-content
folder. (See Figure 6-6.)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.
wp-config.php
on your computer with a text editor, and add the following line below the define( 'MULTISITE', true );
line:
define( 'SUNRISE', 'on' );
Save the file, and upload it to your website.
The plugin is available (and running) on your network immediately.
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.
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:
http://reverseip.domaintools.com
.Write down the IP address displayed.
Figure 6-7 displays the IP address of Google.com (172.217.3.164).
FIGURE 6-7: Reverse IP record revealing the IP address of Google.com.
To map a domain to a site in your network, here’s what you need to do:
Click the Domain Mapping link on the Tools menu.
The Domain Mapping screen appears.
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.
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.
FIGURE 6-8: The Domain Mapping: Domains screen maps domains from a single location.
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.
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:
/etc/httpd/
by typing
cd /etc/httpd/
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.)
<VirtualHost *:80>
/etc/init.d/apache restart
Now you can map domains in volume by following these steps:
Click the DNS records.
(Refer to Figure 6-5 earlier in this chapter.)
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.
Choose Network Admin⇒ Settings⇒ Domains from your WordPress Dashboard.
The Domain Mapping: Domains page appears, as shown in Figure 6-10.
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.
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.
Click Save.
The page refreshes and shows you a list of mapped domains.
FIGURE 6-9: Domain A records.
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.
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:
Choose Network Admin⇒ Sites.
The Edit Site screen appears in your Network Admin Dashboard.
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.
Click the Settings tab of the Edit Site screen.
This tab displays various settings for the site you’re editing. (See Figure 6-12.)
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.
FIGURE 6-11: The Edit link for individual sites.
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.
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
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:
mynewnetwork
.com
)/home/
mynewnetwork
/public_html/
)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.