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.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.2</p> 20<img alt="" src="/images/feather.gif" /></div> 21<div class="up"><a href="./"><img title="<-" alt="<-" src="/images/left.gif" /></a></div> 22<div id="path"> 23<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.2</a> > <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"> en </a> | 28<a href="/tr/mod/mod_vhost_alias.html" hreflang="tr" rel="alternate" title="T�rk�e"> tr </a></p> 29</div> 30<table class="module"><tr><th><a href="module-dict.html#Description">Description:</a></th><td>Provides for dynamically configured mass virtual 31hosting</td></tr> 32<tr><th><a href="module-dict.html#Status">Status:</a></th><td>Extension</td></tr> 33<tr><th><a href="module-dict.html#ModuleIdentifier">Module�Identifier:</a></th><td>vhost_alias_module</td></tr> 34<tr><th><a href="module-dict.html#SourceFile">Source�File:</a></th><td>mod_vhost_alias.c</td></tr></table> 35<h3>Summary</h3> 36 37 <p>This module creates dynamically configured virtual hosts, by 38 allowing the IP address and/or the <code>Host:</code> header of 39 the HTTP request to be used as part of the pathname to 40 determine what files to serve. This allows for easy use of a 41 huge number of virtual hosts with similar configurations.</p> 42 43 <div class="note"><h3>Note</h3> 44 <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 45 used for translating URIs to filenames, they will override the 46 directives of <code class="module"><a href="/mod/mod_vhost_alias.html">mod_vhost_alias</a></code> described below. For 47 example, the following configuration will map <code> 48 /cgi-bin/script.pl</code> to <code> 49 /usr/local/apache2/cgi-bin/script.pl</code> in all cases:</p> 50 51 <div class="example"><p><code> 52 ScriptAlias /cgi-bin/ /usr/local/apache2/cgi-bin/<br /> 53 VirtualScriptAlias /never/found/%0/cgi-bin/ 54 </code></p></div> 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 <div class="example"><p><code> 147 UseCanonicalName Off<br /> 148 VirtualDocumentRoot /usr/local/apache/vhosts/%0 149 </code></p></div> 150 151 <p>A request for 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>. 155 </p> 156 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> 161 162 <div class="example"><p><code> 163 UseCanonicalName Off<br /> 164 VirtualDocumentRoot /usr/local/apache/vhosts/%3+/%2.1/%2.2/%2.3/%2 165 </code></p></div> 166 167 <p>A request for 168 <code>http://www.domain.example.com/directory/file.html</code> 169 will be satisfied by the file 170 <code>/usr/local/apache/vhosts/example.com/d/o/m/domain/directory/file.html</code>.</p> 171 172 <p>A more even spread of files can be achieved by hashing from the 173 end of the name, for example: </p> 174 175<div class="example"><p><code> 176 VirtualDocumentRoot /usr/local/apache/vhosts/%3+/%2.-1/%2.-2/%2.-3/%2 177</code></p></div> 178 179 <p>The example request would come from 180 <code>/usr/local/apache/vhosts/example.com/n/i/a/domain/directory/file.html</code>.</p> 181 182 <p>Alternatively you might use: </p> 183 184<div class="example"><p><code> 185 VirtualDocumentRoot /usr/local/apache/vhosts/%3+/%2.1/%2.2/%2.3/%2.4+ 186</code></p></div> 187 188 <p>The example request would come from 189 <code>/usr/local/apache/vhosts/example.com/d/o/m/ain/directory/file.html</code>.</p> 190 191 <p>For IP-based virtual hosting you might use the following in 192 your configuration file:</p> 193 194 <div class="example"><p><code> 195 UseCanonicalName DNS<br /> 196 VirtualDocumentRootIP /usr/local/apache/vhosts/%1/%2/%3/%4/docs<br /> 197 VirtualScriptAliasIP /usr/local/apache/vhosts/%1/%2/%3/%4/cgi-bin 198 </code></p></div> 199 200 <p>A request for 201 <code>http://www.domain.example.com/directory/file.html</code> 202 would be satisfied by the file 203 <code>/usr/local/apache/vhosts/10/20/30/40/docs/directory/file.html</code> 204 if the IP address of <code>www.domain.example.com</code> were 205 10.20.30.40. A request for 206 <code>http://www.domain.example.com/cgi-bin/script.pl</code> would 207 be satisfied by executing the program 208 <code>/usr/local/apache/vhosts/10/20/30/40/cgi-bin/script.pl</code>.</p> 209 210 <p>If you want to include the <code>.</code> character in a 211 <code>VirtualDocumentRoot</code> directive, but it clashes with 212 a <code>%</code> directive, you can work around the problem in 213 the following way:</p> 214 215<div class="example"><p><code> 216 VirtualDocumentRoot /usr/local/apache/vhosts/%2.0.%3.0 217</code></p></div> 218 219 <p>A request for 220 <code>http://www.domain.example.com/directory/file.html</code> 221 will be satisfied by the file 222 <code>/usr/local/apache/vhosts/domain.example/directory/file.html</code>.</p> 223 224 <p>The <code class="directive"><a href="/mod/mod_log_config.html#logformat">LogFormat</a></code> 225 directives <code>%V</code> and <code>%A</code> are useful 226 in conjunction with this module.</p> 227</div> 228<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 229<div class="directive-section"><h2><a name="VirtualDocumentRoot" id="VirtualDocumentRoot">VirtualDocumentRoot</a> <a name="virtualdocumentroot" id="virtualdocumentroot">Directive</a></h2> 230<table class="directive"> 231<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Dynamically configure the location of the document root 232for a given virtual host</td></tr> 233<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>VirtualDocumentRoot <em>interpolated-directory</em>|none</code></td></tr> 234<tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>VirtualDocumentRoot none</code></td></tr> 235<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr> 236<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr> 237<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_vhost_alias</td></tr> 238</table> 239 240 <p>The <code class="directive">VirtualDocumentRoot</code> directive allows you to 241 determine where Apache will find your documents based on the 242 value of the server name. The result of expanding 243 <em>interpolated-directory</em> is used as the root of the 244 document tree in a similar manner to the <code class="directive"><a href="/mod/core.html#documentroot">DocumentRoot</a></code> directive's argument. 245 If <em>interpolated-directory</em> is <code>none</code> then 246 <code class="directive">VirtualDocumentRoot</code> is turned off. This directive 247 cannot be used in the same context as <code class="directive"><a href="#virtualdocumentrootip">VirtualDocumentRootIP</a></code>.</p> 248 249 250</div> 251<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 252<div class="directive-section"><h2><a name="VirtualDocumentRootIP" id="VirtualDocumentRootIP">VirtualDocumentRootIP</a> <a name="virtualdocumentrootip" id="virtualdocumentrootip">Directive</a></h2> 253<table class="directive"> 254<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Dynamically configure the location of the document root 255for a given virtual host</td></tr> 256<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>VirtualDocumentRootIP <em>interpolated-directory</em>|none</code></td></tr> 257<tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>VirtualDocumentRootIP none</code></td></tr> 258<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr> 259<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr> 260<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_vhost_alias</td></tr> 261</table> 262 263<p>The <code class="directive">VirtualDocumentRootIP</code> directive is like the 264 <code class="directive"><a href="#virtualdocumentroot">VirtualDocumentRoot</a></code> 265 directive, except that it uses the IP address of the server end 266 of the connection for directory interpolation instead of the server 267 name.</p> 268 269</div> 270<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 271<div class="directive-section"><h2><a name="VirtualScriptAlias" id="VirtualScriptAlias">VirtualScriptAlias</a> <a name="virtualscriptalias" id="virtualscriptalias">Directive</a></h2> 272<table class="directive"> 273<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Dynamically configure the location of the CGI directory for 274a given virtual host</td></tr> 275<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>VirtualScriptAlias <em>interpolated-directory</em>|none</code></td></tr> 276<tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>VirtualScriptAlias none</code></td></tr> 277<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr> 278<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr> 279<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_vhost_alias</td></tr> 280</table> 281 282 <p>The <code class="directive">VirtualScriptAlias</code> directive allows you to 283 determine where Apache will find CGI scripts in a similar 284 manner to <code class="directive"><a href="#virtualdocumentroot">VirtualDocumentRoot</a></code> does for other documents. It matches 285 requests for URIs starting <code>/cgi-bin/</code>, much like <code class="directive"><a href="/mod/mod_alias.html#scriptalias">ScriptAlias</a></code> 286 <code>/cgi-bin/</code> would.</p> 287 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="VirtualScriptAliasIP" id="VirtualScriptAliasIP">VirtualScriptAliasIP</a> <a name="virtualscriptaliasip" id="virtualscriptaliasip">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>VirtualScriptAliasIP <em>interpolated-directory</em>|none</code></td></tr> 296<tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>VirtualScriptAliasIP 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">VirtualScriptAliasIP</code> directive is like the 303 <code class="directive"><a href="#virtualscriptalias">VirtualScriptAlias</a></code> 304 directive, except that it uses the IP address of the server end 305 of the connection for directory interpolation instead of the server 306 name.</p> 307 308 309</div> 310</div> 311<div class="bottomlang"> 312<p><span>Available Languages: </span><a href="/en/mod/mod_vhost_alias.html" title="English"> en </a> | 313<a href="/tr/mod/mod_vhost_alias.html" hreflang="tr" rel="alternate" title="T�rk�e"> tr </a></p> 314</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> 315<script type="text/javascript"><!--//--><![CDATA[//><!-- 316var comments_shortname = 'httpd'; 317var comments_identifier = 'http://httpd.apache.org/docs/2.2/mod/mod_vhost_alias.html'; 318(function(w, d) { 319 if (w.location.hostname.toLowerCase() == "httpd.apache.org") { 320 d.write('<div id="comments_thread"><\/div>'); 321 var s = d.createElement('script'); 322 s.type = 'text/javascript'; 323 s.async = true; 324 s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier; 325 (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s); 326 } 327 else { 328 d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>'); 329 } 330})(window, document); 331//--><!]]></script></div><div id="footer"> 332<p class="apache">Copyright 2013 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> 333<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[//><!-- 334if (typeof(prettyPrint) !== 'undefined') { 335 prettyPrint(); 336} 337//--><!]]></script> 338</body></html>