Configuring an apache virtualhost to link to another's virtualhost's subdomain

Posted by Laurent Van Winckel on Server Fault See other posts from Server Fault or by Laurent Van Winckel
Published on 2010-11-05T02:08:49Z Indexed on 2011/01/12 5:55 UTC
Read the original article Hit count: 262

Filed under:
|

I have a domain on my server (on its own virtualhost), e.g. domain.com, which has a lot of subdomains with content on it.

  • sub1.domain.com
  • sub2.domain.com

This virtualhost looks like this:

 ServerAdmin [email protected]
 ServerName domain.com
 ServerAlias *.domain.com
 DocumentRoot /var/www/domain.com/public_html/

I want to put other domains on the server and have each of them link to a specific subdomain on domain.com. I don't want it to redirect. I want a similar behavior as the [L,PT] flags on mod rewrite.

I've tried this:

 ServerName otherdomain.com
 ReWriteEngine on
 RewriteCond %{HTTP_HOST} ^otherdomain.com$ [NC]
 RewriteRule ^(.*)$ http://sub1.domain.com/$1 [PT,L]

But it is giving me a 400 Bad request error.

How would I configure such a virtualhost?

© Server Fault or respective owner

Related posts about apache

Related posts about virtualhosts