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 admin@domain.com
 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?

1 Answer 1


If the following doesn't do what you want, please explain why.

<Virtualhost ...>
  ServerName sub1.domain.com
  DocumentRoot /www/sub1

<Virtualhost ...>
  Servername otherdomain.com
  DocumentRoot /www/sub1
  • The subdomains on domain.com are created dynamically (my database stores which subdomains exist), that's why I'm using ServerAlias *.domain.com. There is no physical document root for every subdomain. Nov 5, 2010 at 12:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.