1<?xml version="1.0" encoding="ISO-8859-1"?>
2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
4        XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
5              This file is generated from xml source: DO NOT EDIT
6        XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
7      -->
8<title>mod_vhost_alias - Apache HTTP Server</title>
9<link href="/style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
10<link href="/style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
11<link href="/style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" /><link rel="stylesheet" type="text/css" href="/style/css/prettify.css" />
12<script src="/style/scripts/prettify.min.js" type="text/javascript">
13</script>
14
15<link href="/images/favicon.ico" rel="shortcut icon" /></head>
16<body>
17<div id="page-header">
18<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p>
19<p class="apache">Apache HTTP Server Version 2.4</p>
20<img alt="" src="/images/feather.gif" /></div>
21<div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="/images/left.gif" /></a></div>
22<div id="path">
23<a href="http://www.apache.org/">Apache</a> &gt; <a href="http://httpd.apache.org/">HTTP Server</a> &gt; <a href="http://httpd.apache.org/docs/">Documentation</a> &gt; <a href="../">Version 2.4</a> &gt; <a href="./">Modules</a></div>
24<div id="page-content">
25<div id="preamble"><h1>Apache Module mod_vhost_alias</h1>
26<div class="toplang">
27<p><span>Available Languages: </span><a href="/en/mod/mod_vhost_alias.html" title="English">&nbsp;en&nbsp;</a> |
28<a href="/fr/mod/mod_vhost_alias.html" hreflang="fr" rel="alternate" title="Fran�ais">&nbsp;fr&nbsp;</a> |
29<a href="/tr/mod/mod_vhost_alias.html" hreflang="tr" rel="alternate" title="T�rk�e">&nbsp;tr&nbsp;</a></p>
30</div>
31<table class="module"><tr><th><a href="module-dict.html#Description">Description:</a></th><td>Provides for dynamically configured mass virtual
32hosting</td></tr>
33<tr><th><a href="module-dict.html#Status">Status:</a></th><td>Extension</td></tr>
34<tr><th><a href="module-dict.html#ModuleIdentifier">Module�Identifier:</a></th><td>vhost_alias_module</td></tr>
35<tr><th><a href="module-dict.html#SourceFile">Source�File:</a></th><td>mod_vhost_alias.c</td></tr></table>
36<h3>Summary</h3>
37
38    <p>This module creates dynamically configured virtual hosts, by
39    allowing the IP address and/or the <code>Host:</code> header of
40    the HTTP request to be used as part of the pathname to
41    determine what files to serve. This allows for easy use of a
42    huge number of virtual hosts with similar configurations.</p>
43
44    <div class="note"><h3>Note</h3>
45      <p>If <code class="module"><a href="/mod/mod_alias.html">mod_alias</a></code> or <code class="module"><a href="/mod/mod_userdir.html">mod_userdir</a></code> are
46      used for translating URIs to filenames, they will override the
47      directives of <code class="module"><a href="/mod/mod_vhost_alias.html">mod_vhost_alias</a></code> described below. For
48      example, the following configuration will map <code>
49      /cgi-bin/script.pl</code> to <code>
50      /usr/local/apache2/cgi-bin/script.pl</code> in all cases:</p>
51
52      <pre class="prettyprint lang-config">ScriptAlias /cgi-bin/ /usr/local/apache2/cgi-bin/
53VirtualScriptAlias /never/found/%0/cgi-bin/</pre>
54
55    </div>
56</div>
57<div id="quickview"><h3 class="directives">Directives</h3>
58<ul id="toc">
59<li><img alt="" src="/images/down.gif" /> <a href="#virtualdocumentroot">VirtualDocumentRoot</a></li>
60<li><img alt="" src="/images/down.gif" /> <a href="#virtualdocumentrootip">VirtualDocumentRootIP</a></li>
61<li><img alt="" src="/images/down.gif" /> <a href="#virtualscriptalias">VirtualScriptAlias</a></li>
62<li><img alt="" src="/images/down.gif" /> <a href="#virtualscriptaliasip">VirtualScriptAliasIP</a></li>
63</ul>
64<h3>Topics</h3>
65<ul id="topics">
66<li><img alt="" src="/images/down.gif" /> <a href="#interpol">Directory Name Interpolation</a></li>
67<li><img alt="" src="/images/down.gif" /> <a href="#examples">Examples</a></li>
68</ul><h3>See also</h3>
69<ul class="seealso">
70<li><code class="directive"><a href="/mod/core.html#usecanonicalname">UseCanonicalName</a></code></li>
71<li><a href="/vhosts/mass.html">Dynamically configured mass
72    virtual hosting</a></li>
73</ul><ul class="seealso"><li><a href="#comments_section">Comments</a></li></ul></div>
74<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
75<div class="section">
76<h2><a name="interpol" id="interpol">Directory Name Interpolation</a></h2>
77    
78
79    <p>All the directives in this module interpolate a string into
80    a pathname. The interpolated string (henceforth called the
81    "name") may be either the server name (see the <code class="directive"><a href="/mod/core.html#usecanonicalname">UseCanonicalName</a></code>
82    directive for details on how this is determined) or the IP
83    address of the virtual host on the server in dotted-quad
84    format. The interpolation is controlled by specifiers inspired
85    by <code>printf</code> which have a number of formats:</p>
86
87<table>
88
89<tr><td><code>%%</code></td>
90<td>insert a <code>%</code></td></tr>
91
92<tr><td><code>%p</code></td>
93<td>insert the port number of the virtual host</td></tr>
94
95<tr><td><code>%N.M</code></td>
96<td>insert (part of) the name</td></tr>
97
98</table>
99
100    <p><code>N</code> and <code>M</code> are used to specify
101    substrings of the name. <code>N</code> selects from the
102    dot-separated components of the name, and <code>M</code>
103    selects characters within whatever <code>N</code> has selected.
104    <code>M</code> is optional and defaults to zero if it isn't
105    present; the dot must be present if and only if <code>M</code>
106    is present. The interpretation is as follows:</p>
107
108    <table>
109      
110      <tr><td><code>0</code></td>
111      <td>the whole name</td></tr>
112
113      <tr><td><code>1</code></td>
114      <td>the first part</td></tr>
115
116      <tr><td><code>2</code></td>
117      <td>the second part</td></tr>
118
119      <tr><td><code>-1</code></td>
120      <td>the last part</td></tr>
121
122      <tr><td><code>-2</code></td>
123      <td>the penultimate part</td></tr>
124
125      <tr><td><code>2+</code></td>
126      <td>the second and all subsequent parts</td></tr>
127
128      <tr><td><code>-2+</code></td>
129      <td>the penultimate and all preceding parts</td></tr>
130
131      <tr><td><code>1+</code> and <code>-1+</code></td>
132      <td>the same as <code>0</code></td></tr>
133    </table>
134
135    <p>If <code>N</code> or <code>M</code> is greater than the number
136    of parts available a single underscore is interpolated. </p>
137
138</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
139<div class="section">
140<h2><a name="examples" id="examples">Examples</a></h2>
141    
142
143    <p>For simple name-based virtual hosts you might use the
144    following directives in your server configuration file:</p>
145
146    <pre class="prettyprint lang-config">UseCanonicalName    Off
147VirtualDocumentRoot /usr/local/apache/vhosts/%0</pre>
148
149
150    <p>A request for
151    <code>http://www.example.com/directory/file.html</code> will be
152    satisfied by the file
153    <code>/usr/local/apache/vhosts/www.example.com/directory/file.html</code>.
154    </p>
155
156    <p>For a very large number of virtual hosts it is a good idea
157    to arrange the files to reduce the size of the
158    <code>vhosts</code> directory. To do this you might use the
159    following in your configuration file:</p>
160
161    <pre class="prettyprint lang-config">UseCanonicalName    Off
162VirtualDocumentRoot /usr/local/apache/vhosts/%3+/%2.1/%2.2/%2.3/%2</pre>
163
164
165    <p>A request for
166    <code>http://www.domain.example.com/directory/file.html</code>
167    will be satisfied by the file
168    <code>/usr/local/apache/vhosts/example.com/d/o/m/domain/directory/file.html</code>.</p>
169
170    <p>A more even spread of files can be achieved by hashing from the
171    end of the name, for example: </p>
172
173<pre class="prettyprint lang-config">VirtualDocumentRoot /usr/local/apache/vhosts/%3+/%2.-1/%2.-2/%2.-3/%2</pre>
174
175
176    <p>The example request would come from
177    <code>/usr/local/apache/vhosts/example.com/n/i/a/domain/directory/file.html</code>.</p>
178
179    <p>Alternatively you might use: </p>
180
181<pre class="prettyprint lang-config">VirtualDocumentRoot /usr/local/apache/vhosts/%3+/%2.1/%2.2/%2.3/%2.4+</pre>
182
183
184    <p>The example request would come from
185    <code>/usr/local/apache/vhosts/example.com/d/o/m/ain/directory/file.html</code>.</p>
186
187<p> A very common request by users is the ability to point multiple domains to multiple 
188document roots without having to worry about the length or number of parts of the 
189hostname being requested. If the requested hostname is <code>sub.www.domain.example.com</code>
190 instead of simply <code>www.domain.example.com</code>, then using %3+ will result in the document
191root being <code>/usr/local/apache/vhosts/domain.example.com/...</code> instead of the
192intended <code>example.com</code> directory. In such cases, it can be beneficial to use 
193the combination <code>%-2.0.%-1.0</code>, which will always yield the domain name and the 
194tld, for example <code>example.com</code> regardless of the number of subdomains appended 
195to the hostname. As such, one can make a configuration that will direct all first, second 
196or third level subdomains to the same directory:
197</p>
198<pre class="prettyprint lang-config">VirtualDocumentRoot "/usr/local/apache/vhosts/%-2.0.%-1.0"</pre>
199
200<p>
201In the example above, both <code>www.example.com</code> as well as <code>www.sub.example.com</code>
202or <code>example.com</code> will all point to <code>/usr/local/apache/vhosts/example.com</code>.
203</p>
204
205    <p>For IP-based virtual hosting you might use the following in
206    your configuration file:</p>
207
208    <pre class="prettyprint lang-config">UseCanonicalName DNS
209VirtualDocumentRootIP /usr/local/apache/vhosts/%1/%2/%3/%4/docs
210VirtualScriptAliasIP  /usr/local/apache/vhosts/%1/%2/%3/%4/cgi-bin</pre>
211
212
213    <p>A request for
214    <code>http://www.domain.example.com/directory/file.html</code>
215    would be satisfied by the file
216    <code>/usr/local/apache/vhosts/10/20/30/40/docs/directory/file.html</code>
217    if the IP address of <code>www.domain.example.com</code> were
218    10.20.30.40. A request for
219    <code>http://www.domain.example.com/cgi-bin/script.pl</code> would
220    be satisfied by executing the program
221    <code>/usr/local/apache/vhosts/10/20/30/40/cgi-bin/script.pl</code>.</p>
222
223    <p>If you want to include the <code>.</code> character in a
224    <code>VirtualDocumentRoot</code> directive, but it clashes with
225    a <code>%</code> directive, you can work around the problem in
226    the following way:</p>
227
228<pre class="prettyprint lang-config">VirtualDocumentRoot /usr/local/apache/vhosts/%2.0.%3.0</pre>
229
230
231    <p>A request for
232    <code>http://www.domain.example.com/directory/file.html</code>
233    will be satisfied by the file
234    <code>/usr/local/apache/vhosts/domain.example/directory/file.html</code>.</p>
235
236    <p>The <code class="directive"><a href="/mod/mod_log_config.html#logformat">LogFormat</a></code>
237    directives <code>%V</code> and <code>%A</code> are useful
238    in conjunction with this module.</p>
239</div>
240<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
241<div class="directive-section"><h2><a name="VirtualDocumentRoot" id="VirtualDocumentRoot">VirtualDocumentRoot</a> <a name="virtualdocumentroot" id="virtualdocumentroot">Directive</a></h2>
242<table class="directive">
243<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Dynamically configure the location of the document root
244for a given virtual host</td></tr>
245<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>VirtualDocumentRoot <em>interpolated-directory</em>|none</code></td></tr>
246<tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>VirtualDocumentRoot none</code></td></tr>
247<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
248<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
249<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_vhost_alias</td></tr>
250</table>
251
252    <p>The <code class="directive">VirtualDocumentRoot</code> directive allows you to
253    determine where Apache HTTP Server will find your documents based on the
254    value of the server name. The result of expanding
255    <em>interpolated-directory</em> is used as the root of the
256    document tree in a similar manner to the <code class="directive"><a href="/mod/core.html#documentroot">DocumentRoot</a></code> directive's argument.
257    If <em>interpolated-directory</em> is <code>none</code> then
258    <code class="directive">VirtualDocumentRoot</code> is turned off. This directive
259    cannot be used in the same context as <code class="directive"><a href="#virtualdocumentrootip">VirtualDocumentRootIP</a></code>.</p>
260
261<div class="warning"><h3>Note</h3>
262<code class="directive">VirtualDocumentRoot</code> will override any <code class="directive"><a href="/mod/core.html#documentroot">DocumentRoot</a></code> directives you may have put in the same 
263context or child contexts. Putting a <code class="directive">VirtualDocumentRoot</code> 
264in the global server scope will effectively override <code class="directive"><a href="/mod/core.html#documentroot">DocumentRoot</a></code> directives in any virtual hosts defined later 
265on, unless you set <code class="directive">VirtualDocumentRoot</code> to <code>None</code> 
266in each virtual host.
267</div>
268
269
270</div>
271<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
272<div class="directive-section"><h2><a name="VirtualDocumentRootIP" id="VirtualDocumentRootIP">VirtualDocumentRootIP</a> <a name="virtualdocumentrootip" id="virtualdocumentrootip">Directive</a></h2>
273<table class="directive">
274<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Dynamically configure the location of the document root
275for a given virtual host</td></tr>
276<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>VirtualDocumentRootIP <em>interpolated-directory</em>|none</code></td></tr>
277<tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>VirtualDocumentRootIP none</code></td></tr>
278<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
279<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
280<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_vhost_alias</td></tr>
281</table>
282
283<p>The <code class="directive">VirtualDocumentRootIP</code> directive is like the
284    <code class="directive"><a href="#virtualdocumentroot">VirtualDocumentRoot</a></code>
285    directive, except that it uses the IP address of the server end
286    of the connection for directory interpolation instead of the server
287    name.</p>
288
289</div>
290<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
291<div class="directive-section"><h2><a name="VirtualScriptAlias" id="VirtualScriptAlias">VirtualScriptAlias</a> <a name="virtualscriptalias" id="virtualscriptalias">Directive</a></h2>
292<table class="directive">
293<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Dynamically configure the location of the CGI directory for
294a given virtual host</td></tr>
295<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>VirtualScriptAlias <em>interpolated-directory</em>|none</code></td></tr>
296<tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>VirtualScriptAlias none</code></td></tr>
297<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
298<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
299<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_vhost_alias</td></tr>
300</table>
301
302    <p>The <code class="directive">VirtualScriptAlias</code> directive allows you to
303    determine where Apache httpd will find CGI scripts in a similar
304    manner to <code class="directive"><a href="#virtualdocumentroot">VirtualDocumentRoot</a></code> does for other documents. It matches
305    requests for URIs starting <code>/cgi-bin/</code>, much like <code class="directive"><a href="/mod/mod_alias.html#scriptalias">ScriptAlias</a></code>
306    <code>/cgi-bin/</code> would.</p>
307
308
309</div>
310<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
311<div class="directive-section"><h2><a name="VirtualScriptAliasIP" id="VirtualScriptAliasIP">VirtualScriptAliasIP</a> <a name="virtualscriptaliasip" id="virtualscriptaliasip">Directive</a></h2>
312<table class="directive">
313<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Dynamically configure the location of the CGI directory for
314a given virtual host</td></tr>
315<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>VirtualScriptAliasIP <em>interpolated-directory</em>|none</code></td></tr>
316<tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>VirtualScriptAliasIP none</code></td></tr>
317<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
318<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
319<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_vhost_alias</td></tr>
320</table>
321
322    <p>The <code class="directive">VirtualScriptAliasIP</code> directive is like the
323    <code class="directive"><a href="#virtualscriptalias">VirtualScriptAlias</a></code>
324    directive, except that it uses the IP address of the server end
325    of the connection for directory interpolation instead of the server
326    name.</p>
327
328    
329</div>
330</div>
331<div class="bottomlang">
332<p><span>Available Languages: </span><a href="/en/mod/mod_vhost_alias.html" title="English">&nbsp;en&nbsp;</a> |
333<a href="/fr/mod/mod_vhost_alias.html" hreflang="fr" rel="alternate" title="Fran�ais">&nbsp;fr&nbsp;</a> |
334<a href="/tr/mod/mod_vhost_alias.html" hreflang="tr" rel="alternate" title="T�rk�e">&nbsp;tr&nbsp;</a></p>
335</div><div class="top"><a href="#page-header"><img src="/images/up.gif" alt="top" /></a></div><div class="section"><h2><a id="comments_section" name="comments_section">Comments</a></h2><div class="warning"><strong>Notice:</strong><br />This is not a Q&amp;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 <a href="http://httpd.apache.org/lists.html">mailing lists</a>.</div>
336<script type="text/javascript"><!--//--><![CDATA[//><!--
337var comments_shortname = 'httpd';
338var comments_identifier = 'http://httpd.apache.org/docs/2.4/mod/mod_vhost_alias.html';
339(function(w, d) {
340    if (w.location.hostname.toLowerCase() == "httpd.apache.org") {
341        d.write('<div id="comments_thread"><\/div>');
342        var s = d.createElement('script');
343        s.type = 'text/javascript';
344        s.async = true;
345        s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
346        (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
347    }
348    else { 
349        d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>');
350    }
351})(window, document);
352//--><!]]></script></div><div id="footer">
353<p class="apache">Copyright 2014 The Apache Software Foundation.<br />Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p>
354<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p></div><script type="text/javascript"><!--//--><![CDATA[//><!--
355if (typeof(prettyPrint) !== 'undefined') {
356    prettyPrint();
357}
358//--><!]]></script>
359</body></html>