Redirect from subdomain to domain + .htaccess
Is it possible that I can customize the RewriteRule for more than one domain.
Like my requirement My real domain name is www.maindomain.com and let's say I have three dominic and subdomains subdomain url example1.maindomain.com example2.maindomain.com example3.maindomain.com
Now I want when the user tries 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 the help.
First, write a condition that matches all of the domain names you want to redirect. Using the consistent portion of the domain, write a rule that rewrites the URLs of the target subdomains. So, given the desired display given in your question, the following should do the trick:
RewriteCond %{HTTP_HOST} ^www\.(example[123])\.com$ [NC]
RewriteRule ^(.*) http://%1.maindomain.com/$1 [L,R]
The aforementioned rewrites from, for example, www.example1.com
to example1.maindomain.com
. Likewise, if you need it the other way around:
RewriteCond %{HTTP_HOST} ^(example[123])\.maindomain\.com$ [NC]
RewriteRule ^(.*) http://www.%1.com/$1 [L,R]
This will overwrite, for example. example2.maindomain.com
before www.example2.com
.
source to share