Map a Separate Domain Name to a WordPress Page or Post

I had a client who wanted to map a domain name directly to a WordPress Page, and not show the WordPress URL.

For example, let’s say you had a WordPress blog with this Page:

But let’s say you want the URL of that post to be

Of course, you could do a simple redirect, but that would result in 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 completely different domain name.  Note, I am assuming in this article that you own the domain name that you want to use (i.e., “”), and that it is pointing to the root of your WordPress site.

My First Try

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 ^(.*)$ [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]

This works! If you type in “” in the browser, it will display the page at, but keep your original URL! Great!!!

As I mentioned, you’ll need to point your domain name at your WordPress root directory. That is, point to

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 ‘’. 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.

Is There a Plugin For This?

Since I first published this article, I found this plugin which seems to do what we need. Another is Page as a Subdomain. I haven’t tried these yet, so if you do, please let me know how they works for you!

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. I am by no means an expert in mod_rewrite, but I hope to be some day. – Brian

46 thoughts on “Map a Separate Domain Name to a WordPress Page or Post

  1. 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

  2. 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?

    1. Hi Biagio,

      You can leave your site_url setting to whatever the rest of the site’s URL is. The .htaccess mod will override it as far as external visitors are concerned.


  3. 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?

  4. 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

  5. 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 >
    And I want to redirect this subpage to a specific domain >

    I tried your method ..but somehow not working. The second domain ( is an alias which redirect to the first domain( 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

  6. Hi, Brian. Thanks for this tutorial.
    One question: would this work for child pages as well? If I created a, would it point to

    1. Hi Gabrielle,

      I don’t think my .htaccess code will work for child pages. But, there is probably a way to rework it so that it would work. I’m not an expert though…


      1. Ok, I’ll look it up, thanks.
        One more (stupid) question. When you say “point your domain name at your WordPress root directory”, does that mean point the nameservers to my host, or is it something else?

        1. Yes. Then, at your host, you might have to point the domain name at a particular directory on your server.


        2. Thanks. Still can’t get it to work, tho. I keep getting a 403 Forbidden error.
          If I do it through cPanel, it redirects just fine, but won’t change the url.
          If I delete the cPanel redirect and edit the htaccess, then I get the error.

  7. 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’?

    1. HI Brett,

      Redirects are not as good for SEO reasons.

      I know I use the term “mask”, but this really isn’t masking. As far as Google is concerned, the new URL is the real actual URL of the site.

      Yes, the domain name has to point at your site’s directory on your server.


  8. 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

    Or would search engines ignore the masked domain and just rank the page underneath your original site (

    Also would you need to remove it from the sitemap on the original site?

    1. Hi Edd,

      Glad you found my article helpful!

      To answer your question, yes, Google will see the canonical URL, I’ve tried this and verified it on Google Analytics.

      Regarding the sitemap, I’m not sure about that. Let me know if you find out.


  9. 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/

    It enables the mod_rewrite which on some occasions providers such as Amazon AWS leave out in their EC2 Linux instances.

    1. Hi Jeff,

      Thank you for your kind words and also for sharing your knowledge with us!!

      Yes, I’ve heard that putting this stuff in the Apache config file is best, also for load time… Not everyone has access to it, but if they do, it’s a good idea.


  10. 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? points to also leads to

    Search engine will see and leading to the same content.

    Wouldn’t you want to use 301 redirect somewhere? [R=301,L]


  11. 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.

    1. 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 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? :-)

    1. Paul:

      What Brian’s done for us is used mod_redirect to do the following:
      Where is a WordPress install
      And /airplanesarecool is a page in that WordPress install

      Rather than market the above URL, Brian can market instead

      And show the content at the /airplanesarecool WordPress page as the 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 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

      Users will see the content that is at

      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


  12. 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 ! :-)

    1. Hi Sylvainmarty,

      The problem might be that the type of page doesn’t work with “page_id”.

      To find out what type of id to use, turn off permalinks (select “Default” in the Permalinks page), then view the URL of the page in question. If it has something besides “?page_id=…”, then use whatever it has. For example, if it is a category, it will have “?cat=…”

      I hope this helps. Let me know how it goes.


Leave a Comment or Ask a Question

This site uses Akismet to reduce spam. Learn how your comment data is processed.