Hosting Tricks: Hosting Unlimited Number of Domains in One-Domain Hosting Account

Posted by Alexey Kovyrin under Admin-tips · русский

Some times we need to use our existing hosting account to (maybe temporarily) place another web-site in it. But what we can do, if our hosting provider allows only one hosting directory and only aliases for main site (as GoDaddy.com does)? We can use the following Apache+mod_rewrite trick to host unlimited number of domains on one hosting directory.

First of all, we need to point our new domain to hosting server IP. If server’s IP is static, we can do it by simple A-record in our DNS-zone control panel:

    new-domain.com  IN A IP.ADD.RE.SS

If you don’t know IP address of hosting server or this address is not permanent (for example, because of some load balancing used by hosting provider), you can use simple trick with CNAME-record in your new DNS-zone:

     new-domain.com  IN CNAME already-hosted-domain.com.

After the first step was finished we have new-domain.com pointed to our hosting provider’s server. Now, we need to add this domain support to hosting server. We can do it by your hosting provider’s “Domain aliases” option or another option with such meaning.

After we have associated our new domain name with existing directory on hosting server (/hosting/dir), everything we need is to do something to force hosting server to use some sub-directory for all requests to new-domain.com (/hosting/dir/new-domain). To do it, we need to put following code into the .htaccess file in /hosting/dir directory:

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_URI} !^/new-domain/
    RewriteCond %{HTTP_HOST} new-domain\.com$
    RewriteRule (.*) http://already-hosted-domain.com/new-domain/$1 [L]

That’s all! After we have created this file, all requests to new-domain.com will be pointed to /hosting/dir/new-domain directory.


Related posts:

  1. Hosting Tricks: How to delegate DNS-management for some subdomain to off-site DNS-server
  2. How To Get “Provider Independent” IP Address For Your Home Server?
  3. How to clone virtual machine with VmWare Server
  4. Educational Podcasts of Universities: MIT and Harvard
  5. Typical Configurations Overview For Nginx HTTP(S) Reverse Proxy/Web Server

5 Responses to this entry

Homo-Adminus Blog » Hosting Tricks: How to delegate DNS-management for some subdomain to off-site DNS-server says:

[...] In one of my last posts about cheap hosting unlimited number of domains, I have described how to point your domain to some sub-directory of an existing hosting account. But sometimes hosting provider requires parking of your DNS name for creating aliases in hosting account. For example, hosting platform, created by me and used on Free Adult hosting Servik.com service, requires your domain’s NS-records to be directed to provider’s own DNS-servers. What can you do if you don’t want to park entire domain to provider’s DNS-servers and want to host only one sub-domain on its servers? [...]

Kpumuk says:

If you need several domains (for example, domain1.com, domain2.com, domain3.com), you need to re-initialize mod_rewrite using RewriteEngine On (otherwise you will receive 500 error):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#domain1.com - base domain

#domain2.com
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} domain2.com
RewriteRule (.*) http://domain1.com/domain2/$1 [L]

#domain3.com
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} domain3.com
RewriteRule (.*) http://domain1.com/domain3/$1 [L]

#specific options for domain1.com will be here