views:

77

answers:

1

I open up a port, let's say port 81 to listen to incoming requests.

If the incoming request is www.myexample.com, then I want to redirect it to

C:\myexamplemain

folder.

If the incoming request is blog.myexample.com, then I want to redirect it to

C:\myexampleblog

folder.

Given that there are a lot of redirection rules for www.myexample.com and blog.myexample.com, I have to create a separate VirtualHost files for these two. So I need a separate configuration files that resolves the DocumentRoot. How to best do this?

+3  A: 

The best way to do this is via virtual hosts.

NameVirtualHost *:81

<VirtualHost *:81>
    DocumentRoot C:\myexamplemain
    ServerName www.myexample.com
</VirtualHost>

<VirtualHost *:81>
    DocumentRoot C:\myexampleblog
    ServerName blog.myexample.com
</VirtualHost>

What file these are in doesn't matter. Apache processes its configuration as if it was all in one file. You can put one bit in one file and the other virtual host bit in another file and it's OK.

Eddie
Won't this need NameVirtualHost *:81at the top, or somewhere in one of the apache config files that gets loaded before either of the virtual hosts?
David Berger
Yes, that is required too. I added it to my answer.
Eddie