Our Domain Mapping plugin makes mapping domains super easy in Multisite. It lets you create as many sites as you want in one WordPress installation and then make them all behave as if they’re separate sites echo on their own domain.
But sometimes you want to map a domain when you’re not running Multisite. You’ve created a site in its own WordPress installation somewhere on your server, maybe in a subdirectory, but you want to direct a domain name to it and have that show up in the browser instead of your own domain with the subfolder or subdomain showing up.
The Domain Mapping plugin only works with Multisite, so you can’t use that to map domains to a single site WordPress installation. But the good news is that you can map a domain to a subdirectory on another domain so it works in just the same way, by using cPanel and changing some WordPress settings.
In this post, I’ll show you how to do it.
This consists of four steps:
- Register the domain and configure it to point to your server if it isn’t already.
- Add the domain to your hosting account, using cPanel.
- Wait for your DNS changes to take effect.
- Edit the URL and settings in your admin screens.
So let’s step through the process.
1. Register the Domain and Point it to Your Server
You can’t do any of this without a domain registered. So begin by registering a domain with the registrar of your choice.
If you register it with your hosting provider, it will automatically direct to their nameservers, so you won’t then have to configure it to point to your server. You can go straight to Step 2.
But if it’s registered elsewhere, for example, if you use different providers for hosting and domains (which can be cost effective and spread risk) or if a client has registered the domain and you’ve created a site for them, you’ll need to configure the DNS settings for the domain.
Go to your domain registrar’s admin screen and edit one of the following options:
If you want every aspect of the domain to point to your hosting server (which for most of us means the domain itself and any email addresses associated with it), then change the nameserver.
I use Big Wet Fish for my domains: here’s their admin screen for changing nameservers:
The screen for your domain registrar will look different but will be essentially similar. You get the nameservers from your hosting provider – they’ll send these when you sign up and you can find them in their admin screens or on cPanel. I use Siteground for my hosting, and they display their nameservers in cPanel:
So that gives me the values I need to add to my registrar’s nameservers admin screen.
Note: If you want to direct a domain to your name servers but have your email hosted elsewhere and you’ve directed the domain to your hosting provider’s name servers, then you can edit the DNS for email (or the MX records) in your hosting provider’s admin screens.
I’ve mentioned above that if you don’t want your domain’s email address hosted with your hosting provider, you can edit this on your hosting account. This means that your DNS for email will redirect twice. If you want to avoid this and either keep email with the domain registrar or direct it somewhere else (such as Gmail) from your registrar’s admin screens, you can do this by editing the CNAME value for your domain instead.
The CNAME points to the domain you want the original domain to redirect to. So if you want mydomain.com to point to myhosting.com/mydomain, you’d add myhosting.com/mydomain in your domain registrar’s admin screens.
Here’s my registrar’s DNS admin screen, showing the options you have:
If you use the CNAME, simply select CNAME and type the address for the new site on your hosting (i.e. myhosting.com/mydomain) in the Address field. The domain will automatically point to the right place and you can skip the next step which is creating the addon domain.
1.6 million WordPress Superheroes read and trust our blog. Join them and get daily posts delivered to your inbox – free!
Another option is to configure the A record for your domain to point to the IP address where your hosting is.
Like the CNAME record, this only affects the website, not email. Use the same DNS screen as you would for the CNAME, select A and type in the IP address. Your hosting provider will give you this or you’ll be able to find it in cPanel or your hosting admin screens.
Note: If you do this you’ll still need to set up the addon domain.
2. Create an Addon Domain
You can skip this step if you used the CNAME option above.
In cPanel, which your hosting provider will give you access to, go to the Domains section:
Select Addon Domains. This will take you to a screen where you need to enter the domain name that you’ve directed to your server:
Type the URL of the domain (without http or www) in the New Domain Name field and the subdirectory where your site is stored in the Document Root field. So using the example above, I’d type mydomain.com and mydomain, respectively.
If you want to create an FTP account for this site, then add the details in the FTP Username field. Create a password for your new domain and click on Add Domain.
3. Wait for DNS to Take Effect
This can take anything from moments to a day or even two, and you have no control over it. You simply have to wait for your changes to propagate, which means that they’re picked up by web servers around the world meaning that your domain will be redirected correctly.
If you want to keep an eye on progress, check out the whatsmydns site, to see where in the world your DNS is resolving correctly. Here’s my site’s DNS:
Note: My DNS points to CloudFlare because I’m using that with our Hummingbird plugin for performance.
If there are any problems, this is a useful tool to track them.
4. Amend Site Settings
Once you’ve redirected your domain, created an addon domain and the DNS changes have taken effect, the redirect will work. When you type mydomain.com into a browser, you’ll be taken to myhosting.com/mydomain.
But the URL in the browser will still show up as myhosting.com/mydomain. You want it to show up as mydomain.com.
To change this go to Settings > General in your WordPress admin screens. The two fields you need to edit are WordPress Address (URL) and Site Address(URL):
Right now, both of these read myhosting.com/mydomain. Edit them so they read mydomain.com, then click Save Changes.
Because you’ve changed your site’s domain (and cookies won’t work), you’ll probably have to log in again. If you find your site doesn’t work properly, then clear your browser cache. Once you’ve done that you’ll find that your domain is mapped to your new site in just the same way as it would be with the Domain Mapping plugin running on Multisite.
Mapping Domains is Easier Than You Think
By following these four steps, you can map a domain you’ve registered to a subdirectory of your hosting account and have it behave as if it’s hosted along with the domain. This can be useful if you need to direct a second or alternative domain to your site and means that you can create multiple instances of WordPress on your hosting account without having to set up multiple hosting accounts each with their own domain. Which will save you money. Result!