views:

588

answers:

1

Hello friends, Is is possible that i can configure RewriteRule for more then one domain.

Like my requirement is My current domain name www.maindomain.com and let say i have three domian and subdomain the subdomain url is example1.maindomain.com example2.maindomain.com example3.maindomain.com

Now i want when ever user try to access www.example1.com it should get the content of example1.maindomain.com and the same for example2, example3

I am using apache + passenger.

Thanks for help.

A: 

First, write a condition that matches all the domain names you want to redirect. Using the matched part of the domain, write a rule that rewrites to the target subdomain URLs. So, given the desired mapping stated in your question, something like the following should do the trick:

RewriteCond %{HTTP_HOST} ^www\.(example[123])\.com$ [NC]
RewriteRule ^(.*) http://%1.maindomain.com/$1 [L,R]

The above rewrites from e.g. www.example1.com to example1.maindomain.com. Similarly, if you need it the other way round:

RewriteCond %{HTTP_HOST} ^(example[123])\.maindomain\.com$ [NC]
RewriteRule ^(.*) http://www.%1.com/$1 [L,R]

This would rewrite e.g. example2.maindomain.com to www.example2.com.

earl