A Sneaky Domain Parking Trick

While making a server change today, I was reminded of a trick that I used back when getting a shared hosting account with unlimited domains was unheard of and add-on domains used to cost an additional monthly fee.

Athough there was a charge for more than one "active" domain on the account, my hosting company didn't charge for parked domains. And I figured out a way to get those parked domains to act just like add-on domains.

The "trick" involves using mod_rewrite to redirect the incoming request to the appropriate directory, by adding this to your root .htaccess file:

RewriteEngine On

RewriteCond   %{HTTP_HOST}  example.net [NC]
RewriteCond   %{REQUEST_URI}   !/exnet/(.*)
RewriteRule   ^(.*)   exnet/$1 [L]

RewriteCond   %{HTTP_HOST}  example.org [NC]
RewriteCond   %{REQUEST_URI}   !/exorg/(.*)
RewriteRule   ^(.*)   exorg/$1 [L]

Each set of conditions looks for a different parked domain in the request. If it's found, and the request doesn't already include the domain's unique directory name, the visitor is redirected to that directory—and, seemingly, a different site—none the wiser. Visitors to example.com, however, see the site for the primary domain.