Virtual hosts ... yet again .domain.com to www.domain.com

Discussion in 'Server Operation' started by wiremind, Jun 2, 2006.

  1. wiremind

    wiremind New Member

    I've spent a lot of time looking for a solution for this problem but havent had any luck getting it to work. So here it goes. I have the following directory structure for my users:

    /home/users/domain1.com/www
    /home/users/domain1.com/sub1
    /home/users/domain1.com/sub2
    /home/users/domain2.com/www
    /home/users/domain3.com/www

    My virtual host looks like this

    <VirtualHost 123.123.123.123:80>

    UseCanonicalName off
    VirtualDocumentRoot /home/users/%2+/%1
    VirtualScriptAlias /home/users/%2+/%1

    </VirtualHost>

    So basically when a user goes to http://www.domain1.com he'll get the content of /home/users/domain1.com/www When he goes to sub1.domain1.com, he'll get /home/users/domain1.com/sub1 So far so good, everything works fine as long as there is a "www" prefix in the url. However when user goes to http://domain1.com i get a 404 error since the requested directory becomes /home/users/com/domain1 which is obviously incorrect.

    Is there a way to add "www" for all domains that do not include "www" such as domain1.com => www.domain1.com I've tried a bunch of rewrite rules but they did not seem to work. Anyone knows a solution? Thanks.
     
  2. falko

    falko Super Moderator Howtoforge Staff

    Why don't you create a vhost for each of your site with a hardcoded document root?
     
  3. wiremind

    wiremind New Member

    Because i have hundreds of them and i need to automate it all.
     
  4. QpoX

    QpoX New Member

    mod_perl and a script that takes the domains from a file or db?
     

Share This Page