Canonical Redirect on Dynamic Mass Virtual Hosts on Apache
Posted
by Josh
on Server Fault
See other posts from Server Fault
or by Josh
Published on 2010-01-24T14:43:10Z
Indexed on
2010/03/29
17:03 UTC
Read the original article
Hit count: 494
I have a Web app on Apache that allows users to point their domain to the server.
Right now I'm using Apache's dynamic mass virtual hosts with an entry VirtualDocumentRoot /www/hosts/%0/docs
So with www.companydomain.com it points to /www/hosts/www.companydomain.com/docs
The problem is when the user goes to companydomain.com it will point to /www/hosts/companydomain.com/docs
Is there an easy way to automatically have Apache check to see if a directory exists for the virtual host, and if not, look for the host name with "www." in front of it? Other subdomains are fine (i.e. abc.domain.com should point to a diff. directory than def.domain.com) but the whole "www" issue is a mystery to me.
I am using dynamic mass virtual hosts so the server does not have to restart after each registration for the application. If there is a different way that is fine as long as apache isn't restarted each time.
How can I accomplish this? Worst case scenario if there were a way to redirect to a "default" location on the server if not found I could always do a check via PHP or something but I feel like that is a bit hacked together and there has to be a more efficient way.
Thanks in advance!
© Server Fault or respective owner