This module creates dynamically configured virtual hosts, by
allowing the IP address and/or the Host:
header of
the HTTP request to be used as part of the pathname to
determine what files to serve. This allows for easy use of a
huge number of virtual hosts with similar configurations.
If
/cgi-bin/script.pl
to
/usr/local/apache2/cgi-bin/script.pl
in all cases:
All the directives in this module interpolate a string into
a pathname. The interpolated string (henceforth called the
"name") may be either the server name (see the printf
which have a number of formats:
%% |
insert a % |
%p |
insert the port number of the virtual host |
%N.M |
insert (part of) the name |
N
and M
are used to specify
substrings of the name. N
selects from the
dot-separated components of the name, and M
selects characters within whatever N
has selected.
M
is optional and defaults to zero if it isn't
present; the dot must be present if and only if M
is present. The interpretation is as follows:
0 |
the whole name |
1 |
the first part |
2 |
the second part |
-1 |
the last part |
-2 |
the penultimate part |
2+ |
the second and all subsequent parts |
-2+ |
the penultimate and all preceding parts |
1+ and -1+ |
the same as 0 |
If N
or M
is greater than the number
of parts available a single underscore is interpolated.
For simple name-based virtual hosts you might use the following directives in your server configuration file:
A request for
http://www.example.com/directory/file.html
will be
satisfied by the file
/usr/local/apache/vhosts/www.example.com/directory/file.html
.
For a very large number of virtual hosts it is a good idea
to arrange the files to reduce the size of the
vhosts
directory. To do this you might use the
following in your configuration file:
A request for
http://www.domain.example.com/directory/file.html
will be satisfied by the file
/usr/local/apache/vhosts/example.com/d/o/m/domain/directory/file.html
.
A more even spread of files can be achieved by hashing from the end of the name, for example:
The example request would come from
/usr/local/apache/vhosts/example.com/n/i/a/domain/directory/file.html
.
Alternatively you might use:
The example request would come from
/usr/local/apache/vhosts/example.com/d/o/m/ain/directory/file.html
.
For IP-based virtual hosting you might use the following in your configuration file:
A request for
http://www.domain.example.com/directory/file.html
would be satisfied by the file
/usr/local/apache/vhosts/10/20/30/40/docs/directory/file.html
if the IP address of www.domain.example.com
were
10.20.30.40. A request for
http://www.domain.example.com/cgi-bin/script.pl
would
be satisfied by executing the program
/usr/local/apache/vhosts/10/20/30/40/cgi-bin/script.pl
.
If you want to include the .
character in a
VirtualDocumentRoot
directive, but it clashes with
a %
directive, you can work around the problem in
the following way:
A request for
http://www.domain.example.com/directory/file.html
will be satisfied by the file
/usr/local/apache/vhosts/domain.example/directory/file.html
.
The %V
and %A
are useful
in conjunction with this module.
The none
then
The
The /cgi-bin/
, much like /cgi-bin/
would.
The