I had a client who wanted to map a domain name (different than the site’s root) directly to a WordPress Page, and not show the WordPress URL.
For example, let’s say you had a WordPress blog with this Page:
http://myblog.com/my-first-post/
But let’s say you want the URL of that post to be http://airplanesarecool.com.
Of course, you could do a simple redirect, but that would result in http://myblog.com/my-first-post being shown as the URL in your browser, not the original domain name.
In this article, I’ll show you how to mask a WordPress page or post with a separate URL with a completely different domain name.
Pointing Your Domains
I am assuming in this article that you own the domain name that you want to use (i.e., “airplanesarecool.com”), and that it is pointing to the root of your WordPress site, but here’s a quick overview of what that entails.
First, you’ll need to go to your DNS records (often, but not always, found at your domain name host), and point the A-record of your naked domain at your server’s IP address (which can be found at your web host). Some DNS providers give you the ability to point your naked domain using a CNAME to a domain name instead of an IP address. That is pretty cool because it means you don’t need to change this again if you change servers and your IP address changes. The Namecheap DNS will let you do this. Sadly, GoDaddy’s DNS doesn’t allow this.
Now the domain is pointing at your server’s IP address, but not at a specific directory. If you’re on cPanel, go to Addon Domains to assign the domain to a directory. On Gridpane, go to the site -> domains in the control panel and create an Alias domain.
Next is the actual domain mapping.
Update: The WordPress Plugin Way
Since I first wrote this blog post, several WordPress plugins have come out that do domain mapping without the need for writing code!
One such plugin is Multiple Domain Mapping on Single Site. I tried this and it works great! The only caveat is that it won’t map a domain with a subdirectory, but there is a paid version that will.
Another domain mapping plugin that works well is Domain Mapping System. It has a paid version that will map subdirectories. I’m using the paid version with subdirectory mapping on about.build (click on Registrars in the main menu for a page on the same site but in different domain).
Yet another plugin that does this is Page as a Subdomain, but I have not tried that one yet.
If you want to do the whole thing “by hand” (i.e., in .htaccess code), AND you’re on an Apache server, then keep reading. But even if you’re using a plugin, you should skip down to the SEO section below for more things you need to do.
My First Try Using .htaccess (Apache only)
Note, this technique will only work on Apache servers. It won’t work on NGINX. There might be a way to get it to work on OLS, but I was unable to. The technique below worked on GoDaddy Apache servers for me.
I a not a mod_rewrite expert, but I knew the answer lay there. After a lot of reading and tinkering, I came up with this code for my .htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^airplanesarecool\.com$ [NC]
RewriteRule ^(.*)$ http://myblog.com/my-first-post/ [NC,L]
This did do the redirect, but it did not mask the URL. That is, the WordPress URL was still showing up in the browser, not the desired domain name.
I Am The One That Masks
After more tinkering, I discovered that the original domain name was preserved only if I redirected to a file at the root level. It wouldn’t work for subdirectories (maybe one of you knows why?)
Armed with that knowledge, I changed my approach to redirect the URL to the raw “non-pretty” WordPress URL, which is basically index.html at the root level with a query string. Thus, I came up with this:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^airplanesarecool\.com$ [NC]
RewriteRule ^(.*)$ index.php?page_id=180 [NC,QSA]
RewriteCond %{HTTP_HOST} ^www\.airplanesarecool\.com$ [NC]
RewriteRule ^(.*)$ index.php?page_id=2218 [NC,QSA]
This works! If you type in “airplanesarecool.com” in the browser, it will display the page at myblog.com/my-first-post, but keep your original URL! Great!!!
If you also need to map subdirectories, use this variation:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^about\.build$ [NC]
RewriteRule !^. index.php?page_id=2 [NC,QSA]
RewriteCond %{HTTP_HOST} ^www\.about\.build$ [NC]
RewriteRule !^. index.php?page_id=2 [NC,QSA]
As I mentioned, you’ll need to point your domain name at your WordPress root directory. That is, point airplanesarecool.com to myblog.com.
Next, place the code above the WordPress code in your .htaccess file at the WordPress root. That is, put it above the line that says:
#BEGIN WordPress
In the fourth line, specify the ID of your WordPress Page or Post. You can find the ID by viewing your Page or Post in edit mode and looking at the URL. It’s in there.
How it Works
The first line simply turns on the redirecting engine, and the second sets the base directory.
The third line is where the magic starts to happen. It says, “look at the ‘HTTP_HOST’ variable and see if it matches ‘airplanesarecool.com’. The “[NC]” means the test is case-insensitive.
If this condition is met, the fourth line redirects the user to index.php?p=180, where 180 is the ID of the WordPress Page or Post. The “QSA” is needed to preserve query strings.
SEO Implications
Domain mapping does present a dilemma for SEO. You probably want the canonical URL of your mapped pages to be the mapped domain, not the original WordPress domain. But, WordPress doesn’t know you mapped the page, so most SEO plugins will just use the original WordPress domain by default.
Luckily most SEO plugins give you the option of overriding the canonical URL with one that you specify. I wasn’t able to get this working properly with Yoast, even though it has the setting. It did work using The SEO Framework plugin for me.
Bottom line, remember to set the canonical URL of your mapped pages in your SEO plugin.
Conclusion
That’s it! Let me know how this worked for you, or if you have any questions, or if you have any corrections or improvements. – Brian

I am a freelance web developer and consultant based in Santa Monica, CA. I’ve been designing websites using WordPress and from scratch using HTML, CSS, PHP, and JavaScript since 2010. I create websites and web applications for businesses, nonprofits, and other organizations. I have a degree in Electrical Engineering (BSEE) from California Institute of Technology and a degree in Engineering Management (MSEM) from Stanford University. If you need help with your site, you can hire me!
thanks it’s working but i want to know that with SSL it’s working but without SSL Is not mean without SSL it’s masking to hosting page
is it possible that without SSL it work as same as SSL?
Hi dhruv,
You might need to add additional code to your .htaccess to redirect http to https. You should be able to easily find that by googling.
Best,
Brian
Hi there,
I have tried this but the fonts weren’t loading in. Anyway to get them to work?
Thanks,
Ronan
Hi Ronan,
Look for errors in Chrome Inspector. That should tell you what the problem is.
Best,
Brian
Thanks for the reply. I am using your code to map a single page from armagh.space website on to the subdomain, test.armagh.space.
There are a bunch of errors in relation to the fonts but they are like the following:
Access to font at ‘https://www.armagh.space/site/wp-content/themes/websiteni-joints/assets/fonts/GillSans-Medium.woff2’ from origin ‘https://test.armagh.space’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.
I’ve Googled the CORS Policy No Access-Control-Allow-Origin and found many people posting code to put in to the .htaccess file, which I tried but wasn’t able to get working.
Any ideas?
I have this working now actually, thanks for the help!
I have this working now actually, thank you!
I want this http://airplanesarecool.com. to show in the browser. not the default domain
Hi there,
Greetings,
I’m using the “Multiple Domain Mapping on single-site” plug-in, and it works fine.
But I have a problem, I have multiple domains and I wanted them all to map to one single page, and it’s not possible I mean this plug-in and other plug-ins allow you to have only one domain for each page!
How can I solve this problem?
I think you may understand better if I say the issue in this way
I want “Domain A”, “Domain B” and “Domain C”, all of them map to “Page A”
Thanks in advance
Thank you! Found the plugin you mentioned in the comments and it was easy to set-up and does the job perfectly. Thanks for the tip!
i tried but the domain yes go to the page i need but when i click to any post still doing this please help
http://ibtech.ca/
i used:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^ibtech\.ca$ [NC]
RewriteRule ^(.*)$ index.php?page_id=230 [NC,QSA]
I tried https://wordpress.org/plugins/multiple-domain-mapping-on-single-site/ today and its working perfectly.
index.php?page_id approach didn’t worked for me.
nginx way:
server {
listen 80;
server_name sub.example.net;
location / {
proxy_pass http://example.net/thePost/;
}
}
you may need to explicitly allow CORS on proxied server:
server {
listen 80;
server_name example.net;
location … {
# for all locations add header as follows
add_header ‘Access-Control-Allow-Origin’ ‘http://sub.example.net’;
}
}
This was really useful. A simple and elegant solution to a problem I have been trying to wrap my head around for a while
Is there a plugin that does this? I want to setup a marketplace where users create their store and could use their own domain
Hello,
I tried it but not working
2 questions:
you said paste before # BEGIN WordPress, so I delete the standard code ( looks like I should, but still asking): standard code is
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
2. I added a page: test and got its page id , which shows as /wp-admin/post.php?post=1061
so what should I put?
I added this code:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^subdoain\.otherdomain\.com$ [NC]
RewriteRule ^(.*)$ index.php?p=1061 [NC,QSA]
SOrry if the questions are naive, but they were not directly clear from the post :)
Thanks in advance
Hi Brian,
Great code, it worked for my http://soeks.store
What should I change to link https://soeks.store
IT worked well for me for one subdomain but when i add another one ie wp_page_id and map to subdomain, it then doesn’t work. Can you please help me?
Hi, just curious… you didn’t have to edit your WordPress configuration for this to work? Like site_url?
This is not working for me, I have created a subdomain for a specific page, this redirects but unable to mask the page url with the subdomain. How can I do that?
I know this has been up for awhile and I understand the concepts. Seems pretty easy to implement for a single redirect. Is it possible to do this for more than one redirect? We had 4 different domain names for 4 different divisions and now we would prefer to have them all under one wordpress template each with their own page displaying their original domain. Hoping you are still willing to offer your input. Thanks
I think I just found a plugin that will do this. Going to check it out and see if it works
Hi Pedalsafari,
Oh, which plugin is that? Let me know if it works!!
Best,
Brian
Hello, I am triying this method on one of my wordpress sites, but it’s not working somehow..
I have a subpage which I want to redirect to a another subdomain:
Maindomain where the WordPress is installed and the subpage > subdomain.example.de/page/supage.
And I want to redirect this subpage to a specific domain > subdomain2.example.de.
I tried your method ..but somehow not working. The second domain (subdomain2.example.de) is an alias which redirect to the first domain(subdomain.example.de) with the wordpress site.
Do I have to consider something else befor doing this..I am not sure what I’m doing wrong :/
Thanks zey
Hi, Brian. Thanks for this tutorial.
One question: would this work for child pages as well? If I created a myblog.com/my-first-post/child-page, would it point to airplanesarecool.com/child-page?
Thanks!
Hi Brian,
Thanks for this. A quick query though – how is this different from doing a cloaked domain redirect to the page?
It seems that rather than the masking occurring through a domain name redirect, that it’s happening via the domain/server instead? Is there any advantage as to why this would be better?
Also, re: the domain name — for this solution to work; is the domain name meant to be ‘parked’ at the domain? Rather than a ‘redirect’?
This is somewhat similar to the thing Im wondering right now, so maybe you can tell me if its possible to have a second URL used for certain pages of a single WordPress install, determined by say a tag or category
so to use your example
http://myblog.com/my-first-post/
but make it display in the address bar and links to
http://secondurl.com/my-first-post/
Hi Brian,
Firstly, thanks for this, it’s bad ass.
Secondly, further to Harleena’s comment above, if you were to use something like Yoast SEO to optimise the masked page, then set the canonical URL as the new domain. Would the page garnish it’s own SEO rank under airplanesarecool.com?
Or would search engines ignore the masked domain and just rank the page underneath your original site (http://myblog.com/my-first-post/)?
Also would you need to remove it from the sitemap on the original site?
I say Brian if you keep up this sort of work with mod_rewrite you’re getting to that “expert” level pretty quickly. Thanks for your share :-)
On a related note I use all my mod_rewrites in the Apache configuration file (httpd.conf for me) as, call me paranoid, i think it’s a bit more secure than appending loads of goodies into htaccess files. Of course anyone with access to their configuration file and rewrites that do not seem to be working please make sure the following is uncommented in your Apache config:
LoadModule rewrite_module modules/mod_rewrite.so
It enables the mod_rewrite which on some occasions providers such as Amazon AWS leave out in their EC2 Linux instances.
Hi Brian,
Just wondering if the search engines could have an issue with the solution.
Will the search engines (including Google) not view this as duplicate content?
airplanesarecool.com points to myblog.com/my-first-post
myblog.com/my-first-post also leads to myblog.com/my-first-post
Search engine will see airplanesarecool.com and myblog.com/my-first-post leading to the same content.
Wouldn’t you want to use 301 redirect somewhere? [R=301,L]
Thanks
I’ve implemented this with a client site, but it only seems to be working in Google Chrome. It doesn’t work on Safari and Firefox. Any thoughts/ideas? I’ve cleared caches on all browsers, but it only works in Chrome.
Hello Aaron
Maybe you can post what you are using here for us to look at? Just “mask” the domains and such out to generics if you want. Also be sure to point your domain (your version of airplanesarecool.com) to your WordPress domain’s root (/). I noticed Chrome is the weirdo of the bunch and trucks right on through this and other incorrect mod_rewrite rules. So much for Google’s adherence to specifications eh? :-)
Hi Brian,
Your fix is awesome – do you think that you can do it so that your page on your blog actually is your homepage? So for example, rather than:
http://airplanesarecool.com/airplanesarecool
you just have
http://airplanesarecool.com/
Can you think of a way of doing that? Would be great!
Cheers,
Paul
Paul:
What Brian’s done for us is used mod_redirect to do the following:
http://airplanesarealright.com/airplanesarecool
Where airplainesarealright.com is a WordPress install
And /airplanesarecool is a page in that WordPress install
Rather than market the above URL, Brian can market instead
http://airplanesarecool.com/
And show the content at the /airplanesarecool WordPress page as the airplanesarecool.com/ root or home page.
What you are asking for is achievable in WordPress already by setting a page, such as /aireplanesarecool as the WordPress installation’s “home page.”
So, if you have your domain which is aireplanesarecool.com and you install WordPress and make a page titled “airplanesarecool” and set it as the static home page in WordPress settings then when you access
http://airplanesarecool.com/
Users will see the content that is at http://airplanesarecool.com/airplanesarecool/
Using canonical URLs (also available in WordPress) is ideal here so search engines do not get confused and serve searchers the correct URL (and don’t tarnish you for spammy practices).
Brian: Side note, after typing “air planes are cool” so many times I truly believe it now! :-)
Hope that helps
Jeff
Hi,
Your tutorial is very simple and accessible ! :-)
Nevertheless, I’ve a problem with the domain name routing.
I gona explain me :
I want to apply your tutorial to a page which use a custom post type.
But when I put the page id in the .htaccess like you (index.php?page_id=custom_post_page_id), the site send me on 404 not founded… Maybe it’s because I’m using permalink ?
Good continuation ! :-)