Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 it points to /www/hosts/

The problem is when the user goes to it will point to /www/hosts/

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. should point to a diff. directory than 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!

share|improve this question

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 explicitly. This lets people not be shocked when they get a page they do not expect, and it prevents multiple indexing by search engines.

share|improve this answer

line 458 of modules/mappers/mod_vhost_alias.c

if (strncasecmp(name,"www.",4) == 0) {
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.