httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From (Ralf S. Engelschall)
Subject Virtual Hosting w/ mod_rewrite (complete solution?)
Date Thu, 26 Feb 1998 16:07:36 GMT

In the past we have tried to support mass virtual hosting without
<VirtualHost> sections by using mod_rewrite. We have discovered that we need
UseCanonicalName, etc. Now that we have the functionality we should thing
again about this interesting point and try to discover a complete solution we
can present to the users. 

So, I've started from scratch and my current solution looks like the
following. I've still not tested it, but it should be 95% correct. Please fix
me were I'm wrong or where we need to configure more. Please give feedback.

www.vhost1.dom:80  /path/to/docroot/vhost1
www.vhost2.dom:80  /path/to/docroot/vhost2
www.vhostN.dom:80  /path/to/docroot/vhostN

##  httpd.conf
#   use the canonical hostname on redirects, etc.

#   add the virtual host in front of the CLF-format
CustomLog  /path/to/access_log  "%{VHOST}e %h %l %u %t \"%r\" %>s %b"

#   enable the rewriting engine in the main server
RewriteEngine on

#   define two maps: one for fixing the URL and one which defines
#   the available virtual hosts with their corresponding
#   DocumentRoot.
RewriteMap    lowercase    int:tolower
RewriteMap    vhost        txt:/path/to/

#   Now do the actual virtual host mapping
#   via a huge and complicated single rule:
#   1. make sure we don't map for common locations
RewriteCond   %{REQUEST_URL}  !^/commonurl1/.*
RewriteCond   %{REQUEST_URL}  !^/commonurl2/.*
RewriteCond   %{REQUEST_URL}  !^/commonurlN/.*
#   2. make sure we have a Host header, because
#      currently our approach only supports 
#      virtual hosting through this header
RewriteCond   %{HTTP_HOST}  !^$
#   3. lowercase the hostname
RewriteCond   ${lowercase:%{HTTP_HOST}|NONE}  ^(.+)$
#   4. lookup this hostname in and
#      remember it only when it is a path 
#      (and not "NONE" from above)
RewriteCond   ${vhost:%1}  ^(/.*)$
#   5. finally we can map the URL to its docroot location 
#      and remember the virtual host for logging puposes
RewriteRule   ^/(.*)$   %1/$1  [E=VHOST:${lowercase:%{HTTP_HOST}}]

                                       Ralf S. Engelschall

View raw message