July 6, 2024

How to host another domain in yours – Apache htaccess files

I have a personal domain and a business domain. They are both available via the shared hosting package for the personal domain. Here's how it’s done, using Mod_Rewrite in the htaccess files.

Let’s call the hosting personal domain “mother.net” and the “parked” business domain "child.com”. The child.com site is a folder at mother.net: “mother.net/child/”.

In the home directory of mother.net, the htaccess file includes the following:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^.*child\.com
RewriteRule ^(.*)$ /child/$1 [L]

This redirects child.com to mother.net/child.

And the htaccess file in the child.com folder includes this:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^.*child\.com
RewriteCond %{REQUEST_URI} \/child\/
RewriteRule ^(.*)$ http://www.child.com/$1 [R=301,L]

This rewrites the URL with  the subdirectory “/child/” as child.com. (The first rewrite condition prevents it from acting on a URL that already contains child.com. )