Abs
Abs

Reputation: 57916

Virtual Host points to another Virtual Host

HELP! I just setup a virtual host for two sites that have a lot of traffic and I think I just messed something up! Here is the end of my httpd.conf:

NameVirtualHost *
<VirtualHost *>
ServerName www.mydomain.com
DocumentRoot /var/www/html
</VirtualHost>

<VirtualHost *>
ServerName www.mydomain2.com
DocumentRoot /var/www/downloadr
</VirtualHost>

<VirtualHost *>
ServerName mydomain2.com
DocumentRoot /var/www/downloadr
</VirtualHost>

I added the last virtual host to solve the problem of mydomain2.com going to wwww.mydomain.com. HOWEVER, what has happened now is that www.mydomain2.com goes to www.mydomain.com.

Please help!!!

Thanks all

UPDATE

STUPIDITY beyond words - managed to copy one site to two directories and hence the 2 domains pointing to the same place!! OMG this will not happen again. Double check and recheck and recheck and recheck and recheck and recheck........

Btw, why would someone neg rep me for this?

Upvotes: 1

Views: 1112

Answers (2)

HLB
HLB

Reputation: 560

I was also having problems with this it turns out that for ServerName Apache did not like the www prepended. So it should look like this:

<VirtualHost *>
 ServerName mydomain2.com
ServerAlias www.mydomain2.com *.mydomain.com
DocumentRoot "c:/wamp/www" #WAMP INSTALL
</VirtualHost>

Upvotes: 0

David Z
David Z

Reputation: 131560

Instead of adding the third virtual host, add

ServerAlias mydomain2.com

to the second one. So your entire configuration would be basically this:

NameVirtualHost *
<VirtualHost *>
    ServerName www.mydomain.com
    DocumentRoot /var/www/html
</VirtualHost>

<VirtualHost *>
    ServerName www.mydomain2.com
    ServerAlias mydomain2.com
    DocumentRoot /var/www/downloadr
</VirtualHost>

If you want requests for mydomain.com to actually be redirected to www.mydomain.com, so that the user sees the URL change in his/her browser, that can be done with mod_rewrite (but that's the subject of another question, search for it if you like)

Upvotes: 3

Related Questions