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:
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 completely different domain name.  Note, 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.

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:

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:

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!!!

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:

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.

Is There a Plugin For This?

Since I first published this article, I found this plugin which seems to do what we need. I haven’t tried it yet, so if you do, please let me know how it 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



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

    1. Hi Solo Jay,

      I found a WorPress plugin that seems to do this, but I’ve never tried it myself:
      https://wordpress.org/plugins/multiple-domain-mapping-on-single-site/

      Let me know what you think of it if you try it!

      Also, regarding your bigger goal, there are lots of plugins that turn Woocommerce into your own Etsy marketplace, basically:
      https://woocommerce.com/products/product-vendors/
      https://wordpress.org/plugins/yith-woocommerce-product-vendors/
      https://wordpress.org/plugins/wc-vendors/
      https://yithemes.com/themes/plugins/yith-woocommerce-multi-vendor/

      But note that the multiple domain mapping plugin notes say it doesn’t work with WooCommerce….

      Best,
      Brian

Leave a Comment or Ask a Question

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