Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

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

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

<Virtualhost ...>
  Servername otherdomain.com
  DocumentRoot /www/sub1
</Virtualhost>
share|improve this answer
    
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. –  Laurent Van Winckel Nov 5 '10 at 12:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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