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 <meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type" />
6 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
7 This file is generated from xml source: DO NOT EDIT
8 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
10 <title>mod_vhost_alias - Apache HTTP Server Version 2.5</title>
11 <link href="../style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
12 <link href="../style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
13 <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" />
14 <script src="../style/scripts/prettify.min.js" type="text/javascript">
17 <link href="../images/favicon.ico" rel="shortcut icon" /></head>
19 <div id="page-header">
20 <p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/quickreference.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>
21 <p class="apache">Apache HTTP Server Version 2.5</p>
22 <img alt="" src="../images/feather.png" /></div>
23 <div class="up"><a href="./"><img title="<-" alt="<-" src="../images/left.gif" /></a></div>
25 <a href="http://www.apache.org/">Apache</a> > <a href="http://httpd.apache.org/">HTTP Server</a> > <a href="http://httpd.apache.org/docs/">Documentation</a> > <a href="../">Version 2.5</a> > <a href="./">Modules</a></div>
26 <div id="page-content">
27 <div id="preamble"><h1>Apache Module mod_vhost_alias</h1>
29 <p><span>Available Languages: </span><a href="../en/mod/mod_vhost_alias.html" title="English"> en </a> |
30 <a href="../tr/mod/mod_vhost_alias.html" hreflang="tr" rel="alternate" title="Türkçe"> tr </a></p>
32 <table class="module"><tr><th><a href="module-dict.html#Description">Description:</a></th><td>Provides for dynamically configured mass virtual
34 <tr><th><a href="module-dict.html#Status">Status:</a></th><td>Extension</td></tr>
35 <tr><th><a href="module-dict.html#ModuleIdentifier">Module Identifier:</a></th><td>vhost_alias_module</td></tr>
36 <tr><th><a href="module-dict.html#SourceFile">Source File:</a></th><td>mod_vhost_alias.c</td></tr></table>
39 <p>This module creates dynamically configured virtual hosts, by
40 allowing the IP address and/or the <code>Host:</code> header of
41 the HTTP request to be used as part of the pathname to
42 determine what files to serve. This allows for easy use of a
43 huge number of virtual hosts with similar configurations.</p>
45 <div class="note"><h3>Note</h3>
46 <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
47 used for translating URIs to filenames, they will override the
48 directives of <code class="module"><a href="../mod/mod_vhost_alias.html">mod_vhost_alias</a></code> described below. For
49 example, the following configuration will map <code>
50 /cgi-bin/script.pl</code> to <code>
51 /usr/local/apache2/cgi-bin/script.pl</code> in all cases:</p>
53 <pre class="prettyprint lang-config">ScriptAlias "/cgi-bin/" "/usr/local/apache2/cgi-bin/"
54 VirtualScriptAlias "/never/found/%0/cgi-bin/"</pre>
58 <div id="quickview"><h3>Topics</h3>
60 <li><img alt="" src="../images/down.gif" /> <a href="#interpol">Directory Name Interpolation</a></li>
61 <li><img alt="" src="../images/down.gif" /> <a href="#examples">Examples</a></li>
62 </ul><h3 class="directives">Directives</h3>
64 <li><img alt="" src="../images/down.gif" /> <a href="#virtualdocumentroot">VirtualDocumentRoot</a></li>
65 <li><img alt="" src="../images/down.gif" /> <a href="#virtualdocumentrootip">VirtualDocumentRootIP</a></li>
66 <li><img alt="" src="../images/down.gif" /> <a href="#virtualscriptalias">VirtualScriptAlias</a></li>
67 <li><img alt="" src="../images/down.gif" /> <a href="#virtualscriptaliasip">VirtualScriptAliasIP</a></li>
69 <h3>Bugfix checklist</h3><ul class="seealso"><li><a href="https://www.apache.org/dist/httpd/CHANGES_2.4">httpd changelog</a></li><li><a href="https://bz.apache.org/bugzilla/buglist.cgi?bug_status=__open__&list_id=144532&product=Apache%20httpd-2&query_format=specific&order=changeddate%20DESC%2Cpriority%2Cbug_severity&component=mod_vhost_alias">Known issues</a></li><li><a href="https://bz.apache.org/bugzilla/enter_bug.cgi?product=Apache%20httpd-2&component=mod_vhost_alias">Report a bug</a></li></ul><h3>See also</h3>
71 <li><code class="directive"><a href="../mod/core.html#usecanonicalname">UseCanonicalName</a></code></li>
72 <li><a href="../vhosts/mass.html">Dynamically configured mass
73 virtual hosting</a></li>
74 <li><a href="#comments_section">Comments</a></li></ul></div>
75 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
77 <h2><a name="interpol" id="interpol">Directory Name Interpolation</a></h2>
80 <p>All the directives in this module interpolate a string into
81 a pathname. The interpolated string (henceforth called the
82 "name") may be either the server name (see the <code class="directive"><a href="../mod/core.html#usecanonicalname">UseCanonicalName</a></code>
83 directive for details on how this is determined) or the IP
84 address of the virtual host on the server in dotted-quad
85 format. The interpolation is controlled by specifiers inspired
86 by <code>printf</code> which have a number of formats:</p>
90 <tr><td><code>%%</code></td>
91 <td>insert a <code>%</code></td></tr>
93 <tr><td><code>%p</code></td>
94 <td>insert the port number of the virtual host</td></tr>
96 <tr><td><code>%N.M</code></td>
97 <td>insert (part of) the name</td></tr>
101 <p><code>N</code> and <code>M</code> are used to specify
102 substrings of the name. <code>N</code> selects from the
103 dot-separated components of the name, and <code>M</code>
104 selects characters within whatever <code>N</code> has selected.
105 <code>M</code> is optional and defaults to zero if it isn't
106 present; the dot must be present if and only if <code>M</code>
107 is present. The interpretation is as follows:</p>
111 <tr><td><code>0</code></td>
112 <td>the whole name</td></tr>
114 <tr><td><code>1</code></td>
115 <td>the first part</td></tr>
117 <tr><td><code>2</code></td>
118 <td>the second part</td></tr>
120 <tr><td><code>-1</code></td>
121 <td>the last part</td></tr>
123 <tr><td><code>-2</code></td>
124 <td>the penultimate part</td></tr>
126 <tr><td><code>2+</code></td>
127 <td>the second and all subsequent parts</td></tr>
129 <tr><td><code>-2+</code></td>
130 <td>the penultimate and all preceding parts</td></tr>
132 <tr><td><code>1+</code> and <code>-1+</code></td>
133 <td>the same as <code>0</code></td></tr>
136 <p>If <code>N</code> or <code>M</code> is greater than the number
137 of parts available a single underscore is interpolated. </p>
139 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
140 <div class="section">
141 <h2><a name="examples" id="examples">Examples</a></h2>
144 <p>For simple name-based virtual hosts you might use the
145 following directives in your server configuration file:</p>
147 <pre class="prettyprint lang-config">UseCanonicalName Off
148 VirtualDocumentRoot "/usr/local/apache/vhosts/%0"</pre>
152 <code>http://www.example.com/directory/file.html</code> will be
153 satisfied by the file
154 <code>/usr/local/apache/vhosts/www.example.com/directory/file.html</code>.
157 <p>For a very large number of virtual hosts it is a good idea
158 to arrange the files to reduce the size of the
159 <code>vhosts</code> directory. To do this you might use the
160 following in your configuration file:</p>
162 <pre class="prettyprint lang-config">UseCanonicalName Off
163 VirtualDocumentRoot "/usr/local/apache/vhosts/%3+/%2.1/%2.2/%2.3/%2"</pre>
167 <code>http://www.domain.example.com/directory/file.html</code>
168 will be satisfied by the file
169 <code>/usr/local/apache/vhosts/example.com/d/o/m/domain/directory/file.html</code>.</p>
171 <p>A more even spread of files can be achieved by hashing from the
172 end of the name, for example: </p>
174 <pre class="prettyprint lang-config">VirtualDocumentRoot "/usr/local/apache/vhosts/%3+/%2.-1/%2.-2/%2.-3/%2"</pre>
177 <p>The example request would come from
178 <code>/usr/local/apache/vhosts/example.com/n/i/a/domain/directory/file.html</code>.</p>
180 <p>Alternatively you might use: </p>
182 <pre class="prettyprint lang-config">VirtualDocumentRoot "/usr/local/apache/vhosts/%3+/%2.1/%2.2/%2.3/%2.4+"</pre>
185 <p>The example request would come from
186 <code>/usr/local/apache/vhosts/example.com/d/o/m/ain/directory/file.html</code>.</p>
188 <p> A very common request by users is the ability to point multiple domains to multiple
189 document roots without having to worry about the length or number of parts of the
190 hostname being requested. If the requested hostname is <code>sub.www.domain.example.com</code>
191 instead of simply <code>www.domain.example.com</code>, then using %3+ will result in the document
192 root being <code>/usr/local/apache/vhosts/domain.example.com/...</code> instead of the
193 intended <code>example.com</code> directory. In such cases, it can be beneficial to use
194 the combination <code>%-2.0.%-1.0</code>, which will always yield the domain name and the
195 tld, for example <code>example.com</code> regardless of the number of subdomains appended
196 to the hostname. As such, one can make a configuration that will direct all first, second
197 or third level subdomains to the same directory:
199 <pre class="prettyprint lang-config">VirtualDocumentRoot "/usr/local/apache/vhosts/%-2.0.%-1.0"</pre>
202 In the example above, both <code>www.example.com</code> as well as <code>www.sub.example.com</code>
203 or <code>example.com</code> will all point to <code>/usr/local/apache/vhosts/example.com</code>.
206 <p>For IP-based virtual hosting you might use the following in
207 your configuration file:</p>
209 <pre class="prettyprint lang-config">UseCanonicalName DNS
210 VirtualDocumentRootIP "/usr/local/apache/vhosts/%1/%2/%3/%4/docs"
211 VirtualScriptAliasIP "/usr/local/apache/vhosts/%1/%2/%3/%4/cgi-bin"</pre>
215 <code>http://www.domain.example.com/directory/file.html</code>
216 would be satisfied by the file
217 <code>/usr/local/apache/vhosts/10/20/30/40/docs/directory/file.html</code>
218 if the IP address of <code>www.domain.example.com</code> were
219 10.20.30.40. A request for
220 <code>http://www.domain.example.com/cgi-bin/script.pl</code> would
221 be satisfied by executing the program
222 <code>/usr/local/apache/vhosts/10/20/30/40/cgi-bin/script.pl</code>.</p>
224 <p>If you want to include the <code>.</code> character in a
225 <code>VirtualDocumentRoot</code> directive, but it clashes with
226 a <code>%</code> directive, you can work around the problem in
227 the following way:</p>
229 <pre class="prettyprint lang-config">VirtualDocumentRoot "/usr/local/apache/vhosts/%2.0.%3.0"</pre>
233 <code>http://www.domain.example.com/directory/file.html</code>
234 will be satisfied by the file
235 <code>/usr/local/apache/vhosts/domain.example/directory/file.html</code>.</p>
237 <p>The <code class="directive"><a href="../mod/mod_log_config.html#logformat">LogFormat</a></code>
238 directives <code>%V</code> and <code>%A</code> are useful
239 in conjunction with this module.</p>
241 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
242 <div class="directive-section"><h2><a name="VirtualDocumentRoot" id="VirtualDocumentRoot">VirtualDocumentRoot</a> <a name="virtualdocumentroot" id="virtualdocumentroot">Directive</a></h2>
243 <table class="directive">
244 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Dynamically configure the location of the document root
245 for a given virtual host</td></tr>
246 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>VirtualDocumentRoot <em>interpolated-directory</em>|none</code></td></tr>
247 <tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>VirtualDocumentRoot none</code></td></tr>
248 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
249 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
250 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_vhost_alias</td></tr>
253 <p>The <code class="directive">VirtualDocumentRoot</code> directive allows you to
254 determine where Apache HTTP Server will find your documents based on the
255 value of the server name. The result of expanding
256 <em>interpolated-directory</em> is used as the root of the
257 document tree in a similar manner to the <code class="directive"><a href="../mod/core.html#documentroot">DocumentRoot</a></code> directive's argument.
258 If <em>interpolated-directory</em> is <code>none</code> then
259 <code class="directive">VirtualDocumentRoot</code> is turned off. This directive
260 cannot be used in the same context as <code class="directive"><a href="#virtualdocumentrootip">VirtualDocumentRootIP</a></code>.</p>
262 <div class="warning"><h3>Note</h3>
263 <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
264 context or child contexts. Putting a <code class="directive">VirtualDocumentRoot</code>
265 in 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
266 on, unless you set <code class="directive">VirtualDocumentRoot</code> to <code>None</code>
267 in each virtual host.
272 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
273 <div class="directive-section"><h2><a name="VirtualDocumentRootIP" id="VirtualDocumentRootIP">VirtualDocumentRootIP</a> <a name="virtualdocumentrootip" id="virtualdocumentrootip">Directive</a></h2>
274 <table class="directive">
275 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Dynamically configure the location of the document root
276 for a given virtual host</td></tr>
277 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>VirtualDocumentRootIP <em>interpolated-directory</em>|none</code></td></tr>
278 <tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>VirtualDocumentRootIP none</code></td></tr>
279 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
280 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
281 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_vhost_alias</td></tr>
284 <p>The <code class="directive">VirtualDocumentRootIP</code> directive is like the
285 <code class="directive"><a href="#virtualdocumentroot">VirtualDocumentRoot</a></code>
286 directive, except that it uses the IP address of the server end
287 of the connection for directory interpolation instead of the server
291 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
292 <div class="directive-section"><h2><a name="VirtualScriptAlias" id="VirtualScriptAlias">VirtualScriptAlias</a> <a name="virtualscriptalias" id="virtualscriptalias">Directive</a></h2>
293 <table class="directive">
294 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Dynamically configure the location of the CGI directory for
295 a given virtual host</td></tr>
296 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>VirtualScriptAlias <em>interpolated-directory</em>|none</code></td></tr>
297 <tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>VirtualScriptAlias none</code></td></tr>
298 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
299 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
300 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_vhost_alias</td></tr>
303 <p>The <code class="directive">VirtualScriptAlias</code> directive allows you to
304 determine where Apache httpd will find CGI scripts in a similar
305 manner to <code class="directive"><a href="#virtualdocumentroot">VirtualDocumentRoot</a></code> does for other documents. It matches
306 requests for URIs starting <code>/cgi-bin/</code>, much like <code class="directive"><a href="../mod/mod_alias.html#scriptalias">ScriptAlias</a></code>
307 <code>/cgi-bin/</code> would.</p>
311 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
312 <div class="directive-section"><h2><a name="VirtualScriptAliasIP" id="VirtualScriptAliasIP">VirtualScriptAliasIP</a> <a name="virtualscriptaliasip" id="virtualscriptaliasip">Directive</a></h2>
313 <table class="directive">
314 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Dynamically configure the location of the CGI directory for
315 a given virtual host</td></tr>
316 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>VirtualScriptAliasIP <em>interpolated-directory</em>|none</code></td></tr>
317 <tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>VirtualScriptAliasIP none</code></td></tr>
318 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
319 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
320 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_vhost_alias</td></tr>
323 <p>The <code class="directive">VirtualScriptAliasIP</code> directive is like the
324 <code class="directive"><a href="#virtualscriptalias">VirtualScriptAlias</a></code>
325 directive, except that it uses the IP address of the server end
326 of the connection for directory interpolation instead of the server
332 <div class="bottomlang">
333 <p><span>Available Languages: </span><a href="../en/mod/mod_vhost_alias.html" title="English"> en </a> |
334 <a href="../tr/mod/mod_vhost_alias.html" hreflang="tr" rel="alternate" title="Türkçe"> tr </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&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[//><!--
337 var comments_shortname = 'httpd';
338 var comments_identifier = 'http://httpd.apache.org/docs/trunk/mod/mod_vhost_alias.html';
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';
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);
349 d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>');
351 })(window, document);
352 //--><!]]></script></div><div id="footer">
353 <p class="apache">Copyright 2016 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/quickreference.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[//><!--
355 if (typeof(prettyPrint) !== 'undefined') {