From: Rich Bowen <VirtualHost>
sections that are
substantially the same, for example:
The basic idea is to replace all of the static
-
-NameVirtualHost 111.22.33.44
-<VirtualHost 111.22.33.44>
-
- ServerName www.customer-1.com
- DocumentRoot /www/hosts/www.customer-1.com/docs
- ScriptAlias /cgi-bin/ /www/hosts/www.customer-1.com/cgi-bin
-
-</VirtualHost>
-<VirtualHost 111.22.33.44>
-
- ServerName www.customer-2.com
- DocumentRoot /www/hosts/www.customer-2.com/docs
- ScriptAlias /cgi-bin/ /www/hosts/www.customer-2.com/cgi-bin
-
-</VirtualHost>
-# blah blah blah
-<VirtualHost 111.22.33.44>
-
- ServerName www.customer-N.com
- DocumentRoot /www/hosts/www.customer-N.com/docs
- ScriptAlias /cgi-bin/ /www/hosts/www.customer-N.com/cgi-bin
-
+
+NameVirtualHost 111.22.33.44
+<VirtualHost 111.22.33.44>
+ ServerName www.customer-1.com
+ DocumentRoot /www/hosts/www.customer-1.com/docs
+ ScriptAlias /cgi-bin/ /www/hosts/www.customer-1.com/cgi-bin
+</VirtualHost>
+
+<VirtualHost 111.22.33.44>
+ ServerName www.customer-2.com
+ DocumentRoot /www/hosts/www.customer-2.com/docs
+ ScriptAlias /cgi-bin/ /www/hosts/www.customer-2.com/cgi-bin
</VirtualHost>
-
<VirtualHost>
configurations with a mechanism
+<VirtualHost 111.22.33.44>
+ ServerName www.customer-N.com
+ DocumentRoot /www/hosts/www.customer-N.com/docs
+ ScriptAlias /cgi-bin/ /www/hosts/www.customer-N.com/cgi-bin
+</VirtualHost>
+
We wish to replace these multiple
+ <VirtualHost>
blocks with a mechanism
that works them out dynamically. This has a number of
advantages:
mod_rewrite
part work properly; the second half
configures mod_rewrite
to do the actual work.
- There are a couple of especially tricky bits: by default,
- mod_rewrite
runs before other URI translation
- modules (mod_alias
etc.) - so if you wish to use these modules, mod_rewrite
must be configured to accommodate
- them. Also, some magic is required to do a
- per-dynamic-virtual-host equivalent of
- ScriptAlias
.
Because mod_rewrite
runs before other URI translation
+ modules (e.g., mod_alias
), mod_rewrite
must
+ be told to explicitly ignore any URLs that would have been handled
+ by those modules. And, because these rules would otherwise bypass
+ any ScriptAlias
directives, we must have
+ mod_rewrite
explicitly enact those mappings.
# get the server name from the Host: header
@@ -324,8 +319,6 @@ CustomLog logs/access_log vcommon
</Directory>
-# now for the hard bit
-
RewriteEngine On
# a ServerName derived from a Host: header may be any case at all
@@ -342,8 +335,6 @@ RewriteRule ^/(.*)$ /www/hosts/${lowercase:%{SERVER_NAME}}/docs/$1
## and now deal with CGIs - we have to force a handler
RewriteCond %{REQUEST_URI} ^/cgi-bin/
RewriteRule ^/(.*)$ /www/hosts/${lowercase:%{SERVER_NAME}}/cgi-bin/$1 [H=cgi-script]
-
-# that's it!
+NameVirtualHost 111.22.33.44 +<VirtualHost 111.22.33.44> + ServerName www.customer-1.com + DocumentRoot /www/hosts/www.customer-1.com/docs + ScriptAlias /cgi-bin/ /www/hosts/www.customer-1.com/cgi-bin +</VirtualHost> + +<VirtualHost 111.22.33.44> + ServerName www.customer-2.com + DocumentRoot /www/hosts/www.customer-2.com/docs + ScriptAlias /cgi-bin/ /www/hosts/www.customer-2.com/cgi-bin </VirtualHost> + +<VirtualHost 111.22.33.44> + ServerName www.customer-N.com + DocumentRoot /www/hosts/www.customer-N.com/docs + ScriptAlias /cgi-bin/ /www/hosts/www.customer-N.com/cgi-bin +</VirtualHost> +
The basic idea is to replace all of the static
- <VirtualHost>
configurations with a mechanism
+
We wish to replace these multiple
+ <VirtualHost>
blocks with a mechanism
that works them out dynamically. This has a number of
advantages:
mod_rewrite
part work properly; the second half
configures mod_rewrite
to do the actual work.
- There are a couple of especially tricky bits: by default,
- mod_rewrite
runs before other URI translation
- modules (mod_alias
etc.) - so if you wish to use these modules, mod_rewrite
must be configured to accommodate
- them. Also, some magic is required to do a
- per-dynamic-virtual-host equivalent of
- ScriptAlias
.
Because mod_rewrite
runs before other URI translation
+ modules (e.g., mod_alias
), mod_rewrite
must
+ be told to explicitly ignore any URLs that would have been handled
+ by those modules. And, because these rules would otherwise bypass
+ any ScriptAlias
directives, we must have
+ mod_rewrite
explicitly enact those mappings.