I seem to be having a bit of trouble with virtual hosts in Apache.

I have added www.mysite.com to my hosts file in Windows and I see my web server fine.

I then added the below to my conf file, as the very end, I don't know if it matters where it goes!

NameVirtualHost *

<VirtualHost *> 
ServerName unknown
DocumentRoot "C:/xampplite/htdocs"

<VirtualHost www.mysite.com> 
ServerName www.mysite.com
DocumentRoot "C:/xampplite/htdocs/mysite"

So what I am trying to achieve is going to www.mysite.com will bring up /mysite folder and anything else - or just going to will default back to the main htdocs folder.

But it doesn't.

It all ends up going to the mysite folder.

Looking at the error log this occurs on start up:

[Tue Sep 13 19:45:08 2011] [error] VirtualHost _default_:443 -- mixing * ports and non-* ports with a NameVirtualHost address is not supported, proceeding with undefined results

For the record I listen to ports 80 and as lame as it is, 1337.


Try this config:

DocumentRoot "C:/xampplite/htdocs/"

<VirtualHost *:80>
    ServerName www.mysite.com
    ServerAlias www.mysite.com
    DocumentRoot "C:/xampplite/htdocs/mysite"
    <Directory "C:/xampplite/htdocs/mysite">
        allow from all
        Options +Indexes

So when you use: it will go to the default DocumentRoot ("C:/xampplite/htdocs/") and when you use www.mysite.com it will go to: "C:/xampplite/htdocs/mysite". You don't need NameVirtualHost

Your Answer

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