Apache Module mod_vhost_alias
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.
are used for translating URIs to filenames, they will override the directives of mod_userdir
described below. For example, the following configuration will map modvhostalias /cgi-bin/script.pl
to /usr/local/apache2/cgi-bin/script.pl
ScriptAlias /cgi-bin/ /usr/local/apache2/cgi-bin/ VirtualScriptAlias /never/found/%0/cgi-bin/
directive for details on how this is determined) or the IP address of the virtual host on the server in dotted-quad format. The interpolation is controlled by specifiers inspired by UseCanonicalNameprintf
which have a number of formats:
%% | insert a % | %p | insert the port number of the virtual host | %N.M | insert (part of) the name |
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
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:
is greater than the number of parts available a single underscore is interpolated.
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
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
A very common request by users is the ability to point multiple domains to multiple document roots without having to worry about the length or number of parts of the hostname being requested. If the requested hostname is sub.www.domain.example.com
directory. In such cases, it can be beneficial to use the combination %-2.0.%-1.0
, which will always yield the domain name and the tld, for example example.com
regardless of the number of subdomains appended to the hostname. As such, one can make a configuration that will direct all first, second or third level subdomains to the same directory:
In the example above, both www.example.com
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 .
directive, you can work around the problem in the following way:
are useful in conjunction with this module.
directive's argument. If DocumentRootinterpolated-directory is none
is turned off. This directive cannot be used in the same context as
directives you may have put in the same context or child contexts. Putting a VirtualDocumentRoot
in the global server scope will effectively override DocumentRoot
directives in any virtual hosts defined later on, unless you set VirtualDocumentRoot
Modules | Directives | FAQ | Glossary | Sitemap
Apache HTTP Server Version 2.4
Apache Module mod_vhost_alias
Available Languages: en | fr | tr
Directory Name Interpolation
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 UseCanonicalName directive for details on how this is determined) or the IP address of the virtual host on the server in dotted-quad f
Examples
For simple name-based virtual hosts you might use the following directives in your server configuration file:
VirtualDocumentRoot Directive
The VirtualDocumentRoot directive allows you to determine where Apache HTTP Server will find your documents based on the value of the server name. The result of expanding interpolated-directory is used as the root of the document tree in a similar manner to the DocumentRoot directive's argument. If
VirtualDocumentRootIP Directive
The VirtualDocumentRootIP directive is like the VirtualDocumentRoot directive, except that it uses the IP address of the server end of the connection for directory interpolation instead of the server name.
VirtualScriptAlias Directive
The VirtualScriptAlias directive allows you to determine where Apache httpd will find CGI scripts in a similar manner to VirtualDocumentRoot does for other documents. It matches requests for URIs starting /cgi-bin/, much like ScriptAlias /cgi-bin/ would.
VirtualScriptAliasIP Directive
The VirtualScriptAliasIP directive is like the VirtualScriptAlias directive, except that it uses the IP address of the server end of the connection for directory interpolation instead of the server name.