0

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!

2 Answers2

0

I think I would look into the -d directory option for RewriteCond to test if a directory exists for this vhost, and if it does not exist, redirect to www.example.com explicitly. This lets people not be shocked when they get a page they do not expect, and it prevents multiple indexing by search engines.

Michael Graff
  • 6,668
  • 1
  • 24
  • 36
0

line 458 of modules/mappers/mod_vhost_alias.c

if (strncasecmp(name,"www.",4) == 0) {
    name+=4;
}
karmawhore
  • 3,865
  • 18
  • 9