upload apache
[bottlenecks.git] / rubbos / app / apache2 / manual / urlmapping.html.en
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>Mapping URLs to Filesystem Locations - 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" />
12 <link href="./images/favicon.ico" rel="shortcut icon" /></head>
13 <body id="manual-page"><div id="page-header">
14 <p class="menu"><a href="./mod/">Modules</a> | <a href="./mod/directives.html">Directives</a> | <a href="./faq/">FAQ</a> | <a href="./glossary.html">Glossary</a> | <a href="./sitemap.html">Sitemap</a></p>
15 <p class="apache">Apache HTTP Server Version 2.0</p>
16 <img alt="" src="./images/feather.gif" /></div>
17 <div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="./images/left.gif" /></a></div>
18 <div id="path">
19 <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.0</a></div><div id="page-content"><div id="preamble"><h1>Mapping URLs to Filesystem Locations</h1>
20 <div class="toplang">
21 <p><span>Available Languages: </span><a href="./en/urlmapping.html" title="English">&nbsp;en&nbsp;</a> |
22 <a href="./ja/urlmapping.html" hreflang="ja" rel="alternate" title="Japanese">&nbsp;ja&nbsp;</a> |
23 <a href="./ko/urlmapping.html" hreflang="ko" rel="alternate" title="Korean">&nbsp;ko&nbsp;</a> |
24 <a href="./tr/urlmapping.html" hreflang="tr" rel="alternate" title="Türkçe">&nbsp;tr&nbsp;</a></p>
25 </div>
26
27     <p>This document explains how Apache uses the URL of a request
28     to determine the filesystem location from which to serve a
29     file.</p>
30   </div>
31 <div id="quickview"><ul id="toc"><li><img alt="" src="./images/down.gif" /> <a href="#related">Related Modules and Directives</a></li>
32 <li><img alt="" src="./images/down.gif" /> <a href="#documentroot">DocumentRoot</a></li>
33 <li><img alt="" src="./images/down.gif" /> <a href="#outside">Files Outside the DocumentRoot</a></li>
34 <li><img alt="" src="./images/down.gif" /> <a href="#user">User Directories</a></li>
35 <li><img alt="" src="./images/down.gif" /> <a href="#redirect">URL Redirection</a></li>
36 <li><img alt="" src="./images/down.gif" /> <a href="#proxy">Reverse Proxy</a></li>
37 <li><img alt="" src="./images/down.gif" /> <a href="#rewrite">Rewriting Engine</a></li>
38 <li><img alt="" src="./images/down.gif" /> <a href="#notfound">File Not Found</a></li>
39 </ul></div>
40 <div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
41 <div class="section">
42 <h2><a name="related" id="related">Related Modules and Directives</a></h2>
43
44 <table class="related"><tr><th>Related Modules</th><th>Related Directives</th></tr><tr><td><ul><li><code class="module"><a href="./mod/mod_alias.html">mod_alias</a></code></li><li><code class="module"><a href="./mod/mod_proxy.html">mod_proxy</a></code></li><li><code class="module"><a href="./mod/mod_rewrite.html">mod_rewrite</a></code></li><li><code class="module"><a href="./mod/mod_userdir.html">mod_userdir</a></code></li><li><code class="module"><a href="./mod/mod_speling.html">mod_speling</a></code></li><li><code class="module"><a href="./mod/mod_vhost_alias.html">mod_vhost_alias</a></code></li></ul></td><td><ul><li><code class="directive"><a href="./mod/mod_alias.html#alias">Alias</a></code></li><li><code class="directive"><a href="./mod/mod_alias.html#aliasmatch">AliasMatch</a></code></li><li><code class="directive"><a href="./mod/mod_speling.html#checkspelling">CheckSpelling</a></code></li><li><code class="directive"><a href="./mod/core.html#documentroot">DocumentRoot</a></code></li><li><code class="directive"><a href="./mod/core.html#errordocument">ErrorDocument</a></code></li><li><code class="directive"><a href="./mod/core.html#options">Options</a></code></li><li><code class="directive"><a href="./mod/mod_proxy.html#proxypass">ProxyPass</a></code></li><li><code class="directive"><a href="./mod/mod_proxy.html#proxypassreverse">ProxyPassReverse</a></code></li><li><code class="directive"><a href="./mod/mod_alias.html#redirect">Redirect</a></code></li><li><code class="directive"><a href="./mod/mod_alias.html#redirectmatch">RedirectMatch</a></code></li><li><code class="directive"><a href="./mod/mod_rewrite.html#rewritecond">RewriteCond</a></code></li><li><code class="directive"><a href="./mod/mod_rewrite.html#rewritematch">RewriteMatch</a></code></li><li><code class="directive"><a href="./mod/mod_alias.html#scriptalias">ScriptAlias</a></code></li><li><code class="directive"><a href="./mod/mod_alias.html#scriptaliasmatch">ScriptAliasMatch</a></code></li><li><code class="directive"><a href="./mod/mod_userdir.html#userdir">UserDir</a></code></li></ul></td></tr></table>
45 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
46 <div class="section">
47 <h2><a name="documentroot" id="documentroot">DocumentRoot</a></h2>
48
49     <p>In deciding what file to serve for a given request, Apache's
50     default behavior is to take the URL-Path for the request (the part
51     of the URL following the hostname and port) and add it to the end
52     of the <code class="directive"><a href="./mod/core.html#documentroot">DocumentRoot</a></code> specified
53     in your configuration files. Therefore, the files and directories
54     underneath the <code class="directive"><a href="./mod/core.html#documentroot">DocumentRoot</a></code>
55     make up the basic document tree which will be visible from the
56     web.</p>
57
58     <p>Apache is also capable of <a href="vhosts/">Virtual
59     Hosting</a>, where the server receives requests for more than one
60     host. In this case, a different <code class="directive"><a href="./mod/core.html#documentroot">DocumentRoot</a></code> can be specified for each
61     virtual host, or alternatively, the directives provided by the
62     module <code class="module"><a href="./mod/mod_vhost_alias.html">mod_vhost_alias</a></code> can
63     be used to dynamically determine the appropriate place from which
64     to serve content based on the requested IP address or
65     hostname.</p>
66 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
67 <div class="section">
68 <h2><a name="outside" id="outside">Files Outside the DocumentRoot</a></h2>
69
70     <p>There are frequently circumstances where it is necessary to
71     allow web access to parts of the filesystem that are not strictly
72     underneath the <code class="directive"><a href="./mod/core.html#documentroot">DocumentRoot</a></code>. Apache offers several
73     different ways to accomplish this. On Unix systems, symbolic links
74     can bring other parts of the filesystem under the <code class="directive"><a href="./mod/core.html#documentroot">DocumentRoot</a></code>. For security reasons,
75     Apache will follow symbolic links only if the <code class="directive"><a href="./mod/core.html#options">Options</a></code> setting for the relevant
76     directory includes <code>FollowSymLinks</code> or
77     <code>SymLinksIfOwnerMatch</code>.</p>
78
79     <p>Alternatively, the <code class="directive"><a href="./mod/mod_alias.html#alias">Alias</a></code> directive will map any part
80     of the filesystem into the web space. For example, with</p>
81
82 <div class="example"><p><code>Alias /docs /var/web</code></p></div>
83
84     <p>the URL <code>http://www.example.com/docs/dir/file.html</code>
85     will be served from <code>/var/web/dir/file.html</code>. The
86     <code class="directive"><a href="./mod/mod_alias.html#scriptalias">ScriptAlias</a></code> directive
87     works the same way, with the additional effect that all content
88     located at the target path is treated as CGI scripts.</p>
89
90     <p>For situations where you require additional flexibility, you
91     can use the <code class="directive"><a href="./mod/mod_alias.html#aliasmatch">AliasMatch</a></code> and 
92     <code class="directive"><a href="./mod/mod_alias.html#scriptaliasmatch">ScriptAliasMatch</a></code>
93     directives to do powerful regular-expression based matching and
94     substitution. For example,</p>
95
96 <div class="example"><p><code>ScriptAliasMatch ^/~([a-zA-Z0-9]+)/cgi-bin/(.+)
97       /home/$1/cgi-bin/$2</code></p></div>
98
99     <p>will map a request to
100     <code>http://example.com/~user/cgi-bin/script.cgi</code> to the
101     path <code>/home/user/cgi-bin/script.cgi</code> and will treat
102     the resulting file as a CGI script.</p>
103 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
104 <div class="section">
105 <h2><a name="user" id="user">User Directories</a></h2>
106
107     <p>Traditionally on Unix systems, the home directory of a
108     particular <em>user</em> can be referred to as
109     <code>~user/</code>. The module <code class="module"><a href="./mod/mod_userdir.html">mod_userdir</a></code>
110     extends this idea to the web by allowing files under each user's
111     home directory to be accessed using URLs such as the
112     following.</p>
113
114 <div class="example"><p><code>http://www.example.com/~user/file.html</code></p></div>
115
116     <p>For security reasons, it is inappropriate to give direct
117     access to a user's home directory from the web. Therefore, the
118     <code class="directive"><a href="./mod/mod_userdir.html#userdir">UserDir</a></code> directive
119     specifies a directory underneath the user's home directory
120     where web files are located. Using the default setting of
121     <code>Userdir public_html</code>, the above URL maps to a file
122     at a directory like
123     <code>/home/user/public_html/file.html</code> where
124     <code>/home/user/</code> is the user's home directory as
125     specified in <code>/etc/passwd</code>.</p>
126
127     <p>There are also several other forms of the
128     <code>Userdir</code> directive which you can use on systems
129     where <code>/etc/passwd</code> does not contain the location of
130     the home directory.</p>
131
132     <p>Some people find the "~" symbol (which is often encoded on the
133     web as <code>%7e</code>) to be awkward and prefer to use an
134     alternate string to represent user directories. This functionality
135     is not supported by mod_userdir. However, if users' home
136     directories are structured in a regular way, then it is possible
137     to use the <code class="directive"><a href="./mod/mod_alias.html#aliasmatch">AliasMatch</a></code>
138     directive to achieve the desired effect. For example, to make
139     <code>http://www.example.com/upages/user/file.html</code> map to
140     <code>/home/user/public_html/file.html</code>, use the following
141     <code>AliasMatch</code> directive:</p>
142
143 <div class="example"><p><code>AliasMatch ^/upages/([a-zA-Z0-9]+)/?(.*)
144       /home/$1/public_html/$2</code></p></div>
145 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
146 <div class="section">
147 <h2><a name="redirect" id="redirect">URL Redirection</a></h2>
148
149     <p>The configuration directives discussed in the above sections
150     tell Apache to get content from a specific place in the filesystem
151     and return it to the client. Sometimes, it is desirable instead to
152     inform the client that the requested content is located at a
153     different URL, and instruct the client to make a new request with
154     the new URL. This is called <em>redirection</em> and is
155     implemented by the <code class="directive"><a href="./mod/mod_alias.html#redirect">Redirect</a></code> directive. For example, if
156     the contents of the directory <code>/foo/</code> under the
157     <code class="directive"><a href="./mod/core.html#documentroot">DocumentRoot</a></code> are moved
158     to the new directory <code>/bar/</code>, you can instruct clients
159     to request the content at the new location as follows:</p>
160
161 <div class="example"><p><code>Redirect permanent /foo/
162       http://www.example.com/bar/</code></p></div>
163
164     <p>This will redirect any URL-Path starting in
165     <code>/foo/</code> to the same URL path on the
166     <code>www.example.com</code> server with <code>/bar/</code>
167     substituted for <code>/foo/</code>. You can redirect clients to
168     any server, not only the origin server.</p>
169
170     <p>Apache also provides a <code class="directive"><a href="./mod/mod_alias.html#redirectmatch">RedirectMatch</a></code> directive for more
171     complicated rewriting problems. For example, to redirect requests
172     for the site home page to a different site, but leave all other
173     requests alone, use the following configuration:</p>
174
175 <div class="example"><p><code>RedirectMatch permanent ^/$
176       http://www.example.com/startpage.html</code></p></div>
177
178     <p>Alternatively, to temporarily redirect all pages on one site
179     to a particular page on another site, use the following:</p>
180
181 <div class="example"><p><code>RedirectMatch temp .*
182       http://othersite.example.com/startpage.html</code></p></div>
183 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
184 <div class="section">
185 <h2><a name="proxy" id="proxy">Reverse Proxy</a></h2>
186
187 <p>Apache also allows you to bring remote documents into the URL space
188 of the local server.  This technique is called <em>reverse
189 proxying</em> because the web server acts like a proxy server by
190 fetching the documents from a remote server and returning them to the
191 client.  It is different from normal proxying because, to the client,
192 it appears the documents originate at the reverse proxy server.</p>
193
194 <p>In the following example, when clients request documents under the
195 <code>/foo/</code> directory, the server fetches those documents from
196 the <code>/bar/</code> directory on <code>internal.example.com</code>
197 and returns them to the client as if they were from the local
198 server.</p>
199
200 <div class="example"><p><code>
201 ProxyPass /foo/ http://internal.example.com/bar/<br />
202 ProxyPassReverse /foo/ http://internal.example.com/bar/
203 </code></p></div>
204
205 <p>The <code class="directive"><a href="./mod/mod_proxy.html#proxypass">ProxyPass</a></code> configures
206 the server to fetch the appropriate documents, while the
207 <code class="directive"><a href="./mod/mod_proxy.html#proxypassreverse">ProxyPassReverse</a></code>
208 directive rewrites redirects originating at
209 <code>internal.example.com</code> so that they target the appropriate
210 directory on the local server.  It is important to note, however, that
211 links inside the documents will not be rewritten.  So any absolute
212 links on <code>internal.example.com</code> will result in the client
213 breaking out of the proxy server and requesting directly from
214 <code>internal.example.com</code>.</p>
215 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
216 <div class="section">
217 <h2><a name="rewrite" id="rewrite">Rewriting Engine</a></h2>
218
219     <p>When even more powerful substitution is required, the rewriting
220     engine provided by <code class="module"><a href="./mod/mod_rewrite.html">mod_rewrite</a></code>
221     can be useful. The directives provided by this module use
222     characteristics of the request such as browser type or source IP
223     address in deciding from where to serve content. In addition,
224     mod_rewrite can use external database files or programs to
225     determine how to handle a request. The rewriting engine is capable
226     of performing all three types of mappings discussed above:
227     internal redirects (aliases), external redirects, and proxying.
228     Many practical examples employing mod_rewrite are discussed in the
229     <a href="misc/rewriteguide.html">URL Rewriting Guide</a>.</p>
230 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
231 <div class="section">
232 <h2><a name="notfound" id="notfound">File Not Found</a></h2>
233
234     <p>Inevitably, URLs will be requested for which no matching
235     file can be found in the filesystem. This can happen for
236     several reasons. In some cases, it can be a result of moving
237     documents from one location to another. In this case, it is
238     best to use <a href="#redirect">URL redirection</a> to inform
239     clients of the new location of the resource. In this way, you
240     can assure that old bookmarks and links will continue to work,
241     even though the resource is at a new location.</p>
242
243     <p>Another common cause of "File Not Found" errors is
244     accidental mistyping of URLs, either directly in the browser,
245     or in HTML links. Apache provides the module
246     <code class="module"><a href="./mod/mod_speling.html">mod_speling</a></code> (sic) to help with
247     this problem. When this module is activated, it will intercept
248     "File Not Found" errors and look for a resource with a similar
249     filename. If one such file is found, mod_speling will send an
250     HTTP redirect to the client informing it of the correct
251     location. If several "close" files are found, a list of
252     available alternatives will be presented to the client.</p>
253
254     <p>An especially useful feature of mod_speling, is that it will
255     compare filenames without respect to case. This can help
256     systems where users are unaware of the case-sensitive nature of
257     URLs and the unix filesystem. But using mod_speling for
258     anything more than the occasional URL correction can place
259     additional load on the server, since each "incorrect" request
260     is followed by a URL redirection and a new request from the
261     client.</p>
262
263     <p>If all attempts to locate the content fail, Apache returns
264     an error page with HTTP status code 404 (file not found). The
265     appearance of this page is controlled with the
266     <code class="directive"><a href="./mod/core.html#errordocument">ErrorDocument</a></code> directive
267     and can be customized in a flexible manner as discussed in the
268     <a href="custom-error.html">Custom error responses</a> and <a href="misc/custom_errordocs.html">International Server Error
269     Responses</a> documents.</p>
270 </div></div>
271 <div class="bottomlang">
272 <p><span>Available Languages: </span><a href="./en/urlmapping.html" title="English">&nbsp;en&nbsp;</a> |
273 <a href="./ja/urlmapping.html" hreflang="ja" rel="alternate" title="Japanese">&nbsp;ja&nbsp;</a> |
274 <a href="./ko/urlmapping.html" hreflang="ko" rel="alternate" title="Korean">&nbsp;ko&nbsp;</a> |
275 <a href="./tr/urlmapping.html" hreflang="tr" rel="alternate" title="Türkçe">&nbsp;tr&nbsp;</a></p>
276 </div><div id="footer">
277 <p class="apache">Copyright 2009 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>
278 <p class="menu"><a href="./mod/">Modules</a> | <a href="./mod/directives.html">Directives</a> | <a href="./faq/">FAQ</a> | <a href="./glossary.html">Glossary</a> | <a href="./sitemap.html">Sitemap</a></p></div>
279 </body></html>