You will need to take care of the DNS
resolution - Apache does
not handle name resolution. You'll need either to create CNAME
records for each hostname, or a DNS wildcard record. Creating DNS
records is beyond the scope of this document.

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 RewriteCond are captured into the
backreferences %1, %2, etc, while parentheses
used in RewriteRule are
captured into the backreferences $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 mod_vhost_alias instead, as it will much
more gracefully handle anything beyond serving static files, such as any
dynamic content, and Alias resolution.

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 mod_rewrite
features to work out the translation from virtual host to document
root, from a separate configuration file. This provides more
flexibility, but requires more complicated configuration.

Notice:This is not a Q&A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed again by our moderators if they are either implemented or considered invalid/off-topic. Questions on how to manage the Apache HTTP Server should be directed at either our IRC channel, #httpd, on Freenode, or sent to our mailing lists.