urlmapping.html.en revision f3ec420152ca921e4c1ce77782f51b53f659018d
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
This file is generated from xml source: DO NOT EDIT
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
-->
<title>Mapping URLs to Filesystem Locations - Apache HTTP Server</title>
<link href="/style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
<link href="/style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
<body id="manual-page"><div id="page-header">
<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>
<p class="apache">Apache HTTP Server Version 2.3</p>
<div id="path">
<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.3</a></div><div id="page-content"><div id="preamble"><h1>Mapping URLs to Filesystem Locations</h1>
<div class="toplang">
<p><span>Available Languages: </span><a href="/en/urlmapping.html" title="English"> en </a> |
</div>
<p>This document explains how Apache uses the URL of a request
to determine the filesystem location from which to serve a
file.</p>
</div>
<div id="quickview"><ul id="toc"><li><img alt="" src="/images/down.gif" /> <a href="#related">Related Modules and Directives</a></li>
<li><img alt="" src="/images/down.gif" /> <a href="#outside">Files Outside the DocumentRoot</a></li>
</ul></div>
<div class="section">
<h2><a name="related" id="related">Related Modules and Directives</a></h2>
<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_proxy.html#proxypassreversecookiedomain">ProxyPassReverseCookieDomain</a></code></li><li><code class="directive"><a href="/mod/mod_proxy.html#proxypassreversecookiepath">ProxyPassReverseCookiePath</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>
<div class="section">
<h2><a name="documentroot" id="documentroot">DocumentRoot</a></h2>
<p>In deciding what file to serve for a given request, Apache's
default behavior is to take the URL-Path for the request (the part
of the URL following the hostname and port) and add it to the end
of the <code class="directive"><a href="/mod/core.html#documentroot">DocumentRoot</a></code> specified
in your configuration files. Therefore, the files and directories
underneath the <code class="directive"><a href="/mod/core.html#documentroot">DocumentRoot</a></code>
make up the basic document tree which will be visible from the
web.</p>
<p>For example, if <code class="directive"><a href="/mod/core.html#documentroot">DocumentRoot</a></code>
served to the requesting client.</p>
<p>Apache is also capable of <a href="vhosts/">Virtual
Hosting</a>, where the server receives requests for more than one
host. In this case, a different <code class="directive"><a href="/mod/core.html#documentroot">DocumentRoot</a></code> can be specified for each
virtual host, or alternatively, the directives provided by the
be used to dynamically determine the appropriate place from which
to serve content based on the requested IP address or
hostname.</p>
<p>The <code class="directive"><a href="/mod/core.html#documentroot">DocumentRoot</a></code> directive
is set in your main server configuration file
(<code>httpd.conf</code>) and, possibly, once per additional <a href="vhosts/">Virtual Host</a> you create.</p>
<div class="section">
<h2><a name="outside" id="outside">Files Outside the DocumentRoot</a></h2>
<p>There are frequently circumstances where it is necessary to
allow web access to parts of the filesystem that are not strictly
underneath the <code class="directive"><a href="/mod/core.html#documentroot">DocumentRoot</a></code>. Apache offers several
different ways to accomplish this. On Unix systems, symbolic links
can bring other parts of the filesystem under the <code class="directive"><a href="/mod/core.html#documentroot">DocumentRoot</a></code>. For security reasons,
Apache will follow symbolic links only if the <code class="directive"><a href="/mod/core.html#options">Options</a></code> setting for the relevant
directory includes <code>FollowSymLinks</code> or
<code>SymLinksIfOwnerMatch</code>.</p>
<p>Alternatively, the <code class="directive"><a href="/mod/mod_alias.html#alias">Alias</a></code> directive will map any part
of the filesystem into the web space. For example, with</p>
works the same way, with the additional effect that all content
located at the target path is treated as <a class="glossarylink" href="/glossary.html#cgi" title="see glossary">CGI</a> scripts.</p>
<p>For situations where you require additional flexibility, you
and <code class="directive"><a href="/mod/mod_alias.html#scriptaliasmatch">ScriptAliasMatch</a></code>
directives to do powerful <a class="glossarylink" href="/glossary.html#regex" title="see glossary">regular
expression</a> based matching and substitution. For
example,</p>
<div class="example"><p><code>ScriptAliasMatch ^/~([a-zA-Z0-9]+)/cgi-bin/(.+)
<p>will map a request to
the resulting file as a CGI script.</p>
<div class="section">
<h2><a name="user" id="user">User Directories</a></h2>
<p>Traditionally on Unix systems, the home directory of a
particular <em>user</em> can be referred to as
<code>~user/</code>. The module <code class="module"><a href="/mod/mod_userdir.html">mod_userdir</a></code>
extends this idea to the web by allowing files under each user's
home directory to be accessed using URLs such as the
following.</p>
<p>For security reasons, it is inappropriate to give direct
access to a user's home directory from the web. Therefore, the
specifies a directory underneath the user's home directory
where web files are located. Using the default setting of
<code>Userdir public_html</code>, the above URL maps to a file
at a directory like
<p>There are also several other forms of the
<code>Userdir</code> directive which you can use on systems
the home directory.</p>
<p>Some people find the "~" symbol (which is often encoded on the
web as <code>%7e</code>) to be awkward and prefer to use an
alternate string to represent user directories. This functionality
is not supported by mod_userdir. However, if users' home
directories are structured in a regular way, then it is possible
directive to achieve the desired effect. For example, to make
<code>AliasMatch</code> directive:</p>
<div class="example"><p><code>AliasMatch ^/upages/([a-zA-Z0-9]+)/?(.*)
<div class="section">
<h2><a name="redirect" id="redirect">URL Redirection</a></h2>
<p>The configuration directives discussed in the above sections
tell Apache to get content from a specific place in the filesystem
and return it to the client. Sometimes, it is desirable instead to
inform the client that the requested content is located at a
different URL, and instruct the client to make a new request with
the new URL. This is called <em>redirection</em> and is
implemented by the <code class="directive"><a href="/mod/mod_alias.html#redirect">Redirect</a></code> directive. For example, if
the contents of the directory <code>/foo/</code> under the
to the new directory <code>/bar/</code>, you can instruct clients
to request the content at the new location as follows:</p>
<div class="example"><p><code>Redirect permanent /foo/
<p>This will redirect any URL-Path starting in
<code>/foo/</code> to the same URL path on the
substituted for <code>/foo/</code>. You can redirect clients to
any server, not only the origin server.</p>
<p>Apache also provides a <code class="directive"><a href="/mod/mod_alias.html#redirectmatch">RedirectMatch</a></code> directive for more
complicated rewriting problems. For example, to redirect requests
for the site home page to a different site, but leave all other
requests alone, use the following configuration:</p>
<div class="example"><p><code>RedirectMatch permanent ^/$
<p>Alternatively, to temporarily redirect all pages on one site
to a particular page on another site, use the following:</p>
<div class="example"><p><code>RedirectMatch temp .*
<div class="section">
<h2><a name="proxy" id="proxy">Reverse Proxy</a></h2>
<p>Apache also allows you to bring remote documents into the URL space
of the local server. This technique is called <em>reverse
proxying</em> because the web server acts like a proxy server by
fetching the documents from a remote server and returning them to the
client. It is different from normal proxying because, to the client,
it appears the documents originate at the reverse proxy server.</p>
<p>In the following example, when clients request documents under the
<code>/foo/</code> directory, the server fetches those documents from
and returns them to the client as if they were from the local
server.</p>
<div class="example"><p><code>
ProxyPass /foo/ http://internal.example.com/bar/<br />
ProxyPassReverse /foo/ http://internal.example.com/bar/
ProxyPassReverseCookieDomain internal.example.com public.example.com
ProxyPassReverseCookiePath /foo/ /bar/
</code></p></div>
<p>The <code class="directive"><a href="/mod/mod_proxy.html#proxypass">ProxyPass</a></code> configures
the server to fetch the appropriate documents, while the
directive rewrites redirects originating at
directory on the local server. Similarly, the
<code class="directive"><a href="/mod/mod_proxy.html#proxypassreversecookiedomain">ProxyPassReverseCookieDomain</a></code>
and <code class="directive"><a href="/mod/mod_proxy.html#proxypassreversecookiepath">ProxyPassReverseCookiePath</a></code>
rewrite cookies set by the backend server.</p>
<p>It is important to note, however, that
links inside the documents will not be rewritten. So any absolute
breaking out of the proxy server and requesting directly from
is available to rewrite links in HTML and XHTML.</p>
<div class="section">
<h2><a name="rewrite" id="rewrite">Rewriting Engine</a></h2>
<p>When even more powerful substitution is required, the rewriting
can be useful. The directives provided by this module use
characteristics of the request such as browser type or source IP
address in deciding from where to serve content. In addition,
mod_rewrite can use external database files or programs to
determine how to handle a request. The rewriting engine is capable
of performing all three types of mappings discussed above:
internal redirects (aliases), external redirects, and proxying.
Many practical examples employing mod_rewrite are discussed in the
<div class="section">
<h2><a name="notfound" id="notfound">File Not Found</a></h2>
<p>Inevitably, URLs will be requested for which no matching
file can be found in the filesystem. This can happen for
several reasons. In some cases, it can be a result of moving
documents from one location to another. In this case, it is
best to use <a href="#redirect">URL redirection</a> to inform
clients of the new location of the resource. In this way, you
can assure that old bookmarks and links will continue to work,
even though the resource is at a new location.</p>
<p>Another common cause of "File Not Found" errors is
accidental mistyping of URLs, either directly in the browser,
or in HTML links. Apache provides the module
this problem. When this module is activated, it will intercept
"File Not Found" errors and look for a resource with a similar
filename. If one such file is found, mod_speling will send an
HTTP redirect to the client informing it of the correct
location. If several "close" files are found, a list of
available alternatives will be presented to the client.</p>
<p>An especially useful feature of mod_speling, is that it will
compare filenames without respect to case. This can help
systems where users are unaware of the case-sensitive nature of
URLs and the unix filesystem. But using mod_speling for
anything more than the occasional URL correction can place
additional load on the server, since each "incorrect" request
is followed by a URL redirection and a new request from the
client.</p>
<p>If all attempts to locate the content fail, Apache returns
an error page with HTTP status code 404 (file not found). The
appearance of this page is controlled with the
and can be customized in a flexible manner as discussed in the
document.</p>
</div></div>
<div class="bottomlang">
<p><span>Available Languages: </span><a href="/en/urlmapping.html" title="English"> en </a> |
</div><div id="footer">
<p class="apache">Copyright 2008 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>
<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>
</body></html>