This document supplements the
We want to automatically create a virtual host for every hostname which resolves in our domain, without having to create new VirtualHost sections.
In this recipe, we assume that we'll be using the hostname
www.SITE.example.com
for each
user, and serve their content out of
/home/SITE/www
.
RewriteEngine on RewriteMap lowercase int:tolower RewriteCond %{lowercase:%{HTTP_HOST}} ^www\.([^.]+)\.example\.com$ RewriteRule ^(.*) /home/%1/www$1
The internal tolower
RewriteMap directive is used to
ensure that the hostnames being used are all lowercase, so that there is
no ambiguity in the directory structure which must be created.
Parentheses used in a %1
, %2
, etc, while parentheses
used in $1
, $2
,
etc.
As with many techniques discussed in this document, mod_rewrite really
isn't the best way to accomplish this task. You should, instead,
consider using
This extract from httpd.conf
does the same
thing as the first example. The first
half is very similar to the corresponding part above, except for
some changes, required for backward compatibility and to make the
mod_rewrite
part work properly; the second half
configures mod_rewrite
to do the actual work.
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.
This arrangement uses more advanced
The vhost.map
file should look something like
this:
The httpd.conf
should contain the following: