Archive for the ‘Apache’ Category

Name-based Virtual Hosting with Addition of Domain

Wednesday, July 25th, 2007

The Problem: There is an existing domain running on an Apache name-based virtual hosting server (let’s call it domain_1.com, IP:123.123.123.121). Due to some requirement, another existing domain (let’s call it domain_2.com, IP:123.123.123.122) has to show the same content of domain_1.com (keep in mind that all the PHP scripts, Perl scripts, database, etc has to be in place).

The Solution: Since it is name-based virtual hosting, it is not possible to just point the “A” record for domain_2.com and www.domain_2.com to the 123.123.123.122.

The first thing I tried is to use mod_rewrite to try to rewrite the whole domain from www.domain_2.com to www.domain_1.com. However, it seems like if mod_rewrite will change the URL (redirect) if it is starting with “http://”.

After a bit of searching, I found that ServerAlias can be used to make more domain names using a single name-based virtual hosting. What I did is to add in:

<VirtualHost 203.81.56.2:80>
ServerName www.domain_1.com
ServerAlias www.domain_1.com domain_1.com www.domain_2.com domain_2.com

This way after the DNS is pointed to 123.123.123.121 for domain_2.com, it will share the same content (and scripts) with domain_1.com.