urlmapping.html.en revision 181e56d8b348d301d615ccf5465ae600fee2867b
d09f538b07aa757f9e6290bd54d28fc1605725a9nd<?xml version="1.0" encoding="ISO-8859-1"?>
d09f538b07aa757f9e6290bd54d28fc1605725a9nd<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
d09f538b07aa757f9e6290bd54d28fc1605725a9nd<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
5f5d1b4cc970b7f06ff8ef6526128e9a27303d88nd XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
d09f538b07aa757f9e6290bd54d28fc1605725a9nd This file is generated from xml source: DO NOT EDIT
6d9c7d0283713aa8ae15fef7e9bfe2c7bfa73872nd XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
db479b48bd4d75423ed4a45e15b75089d1a8ad72fielding --><title>Mapping URLs to Filesystem Locations - Apache HTTP Server</title><link href="/style/css/manual-sbar-right-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="right sidebar - blue (font 100%)" /><link href="/style/css/manual-sbar-right-90pc.css" rel="alternate stylesheet" media="all" type="text/css" title="right sidebar - blue (font 90%)" /><link href="/style/css/manual-sbar-right-fix15.css" rel="stylesheet" media="all" type="text/css" title="right sidebar - blue (font fix 15)" /><link href="/style/css/manual-sbar-right-fix13.css" rel="alternate stylesheet" media="all" type="text/css" title="right sidebar - blue (font fix 13)" /><link href="/style/css/manual-sbar-right-100pc-b.css" rel="alternate stylesheet" media="all" type="text/css" title="right sidebar - black (font 100%)" /><link href="/style/css/manual-sbar-right-90pc-b.css" rel="alternate stylesheet" media="all" type="text/css" title="right sidebar - black (font 90%)" /><link href="/style/css/manual-sbar-right-fix15-b.css" rel="alternate stylesheet" media="all" type="text/css" title="right sidebar - black (font fix 15)" /><link href="/style/css/manual-sbar-right-fix13-b.css" rel="alternate stylesheet" media="all" type="text/css" title="right sidebar - black (font fix 13)" /><link href="/style/css/manual-sbar-left-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="left sidebar - blue (font 100%)" /><link href="/style/css/manual-sbar-left-90pc.css" rel="alternate stylesheet" media="all" type="text/css" title="left sidebar - blue (font 90%)" /><link href="/style/css/manual-sbar-left-fix15.css" rel="alternate stylesheet" media="all" type="text/css" title="left sidebar - blue (font fix 15)" /><link href="/style/css/manual-sbar-left-fix13.css" rel="alternate stylesheet" media="all" type="text/css" title="left sidebar - blue (font fix 13)" /><link href="/style/css/manual-sbar-left-100pc-b.css" rel="alternate stylesheet" media="all" type="text/css" title="left sidebar - black (font 100%)" /><link href="/style/css/manual-sbar-left-90pc-b.css" rel="alternate stylesheet" media="all" type="text/css" title="left sidebar - black (font 90%)" /><link href="/style/css/manual-sbar-left-fix15-b.css" rel="alternate stylesheet" media="all" type="text/css" title="left sidebar - black (font fix 15)" /><link href="/style/css/manual-sbar-left-fix13-b.css" rel="alternate stylesheet" media="all" type="text/css" title="left sidebar - black (font fix 13)" /><link href="/style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="loose style - blue (font 100%)" /><link href="/style/css/manual-loose-90pc.css" rel="alternate stylesheet" media="all" type="text/css" title="loose style - blue (font 90%)" /><link href="/style/css/manual-loose-fix15.css" rel="alternate stylesheet" media="all" type="text/css" title="loose style - blue (font fix 15)" /><link href="/style/css/manual-loose-fix13.css" rel="alternate stylesheet" media="all" type="text/css" title="loose style - blue (font fix 13)" /><link href="/style/css/manual-loose-100pc-b.css" rel="alternate stylesheet" media="all" type="text/css" title="loose style - black (font 100%)" /><link href="/style/css/manual-loose-90pc-b.css" rel="alternate stylesheet" media="all" type="text/css" title="loose style - black (font 90%)" /><link href="/style/css/manual-loose-fix15-b.css" rel="alternate stylesheet" media="all" type="text/css" title="loose style - black (font fix 15)" /><link href="/style/css/manual-loose-fix13-b.css" rel="alternate stylesheet" media="all" type="text/css" title="loose style - black (font fix 13)" /><link href="/images/favicon.ico" rel="shortcut icon" /></head><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.0</p><img alt="" src="/images/feather.gif" /></div><div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="/images/left.gif" /></a></div><div id="path"><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-project/">Documentation</a> &gt; <a href="./">Version 2.0</a></div><div id="page-content"><div id="preamble"><h1>Mapping URLs to Filesystem Locations</h1>
db479b48bd4d75423ed4a45e15b75089d1a8ad72fielding <p>This document explains how Apache uses the URL of a request
db479b48bd4d75423ed4a45e15b75089d1a8ad72fielding to determine the filesystem location from which to serve a
db479b48bd4d75423ed4a45e15b75089d1a8ad72fielding file.</p>
db479b48bd4d75423ed4a45e15b75089d1a8ad72fielding </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="#documentroot">DocumentRoot</a></li><li><img alt="" src="/images/down.gif" /> <a href="#outside">Files Outside the DocumentRoot</a></li><li><img alt="" src="/images/down.gif" /> <a href="#user">User Directories</a></li><li><img alt="" src="/images/down.gif" /> <a href="#redirect">URL Redirection</a></li><li><img alt="" src="/images/down.gif" /> <a href="#proxy">Reverse Proxy</a></li><li><img alt="" src="/images/down.gif" /> <a href="#rewrite">Rewriting Engine</a></li><li><img alt="" src="/images/down.gif" /> <a href="#notfound">File Not Found</a></li></ul></div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div><div class="section"><h2><a name="related" id="related">Related Modules and Directives</a></h2>
db479b48bd4d75423ed4a45e15b75089d1a8ad72fielding
6d9c7d0283713aa8ae15fef7e9bfe2c7bfa73872nd<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>
6d9c7d0283713aa8ae15fef7e9bfe2c7bfa73872nd</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div><div class="section"><h2><a name="documentroot" id="documentroot">DocumentRoot</a></h2>
6d9c7d0283713aa8ae15fef7e9bfe2c7bfa73872nd
6d9c7d0283713aa8ae15fef7e9bfe2c7bfa73872nd <p>In deciding what file to serve for a given request, Apache's
6d9c7d0283713aa8ae15fef7e9bfe2c7bfa73872nd default behavior is to take the URL-Path for the request (the part
6d9c7d0283713aa8ae15fef7e9bfe2c7bfa73872nd of the URL following the hostname and port) and add it to the end
6d9c7d0283713aa8ae15fef7e9bfe2c7bfa73872nd of the <code class="directive"><a href="/mod/core.html#documentroot">DocumentRoot</a></code> specified
6d9c7d0283713aa8ae15fef7e9bfe2c7bfa73872nd in your configuration files. Therefore, the files and directories
6d9c7d0283713aa8ae15fef7e9bfe2c7bfa73872nd underneath the <code class="directive"><a href="/mod/core.html#documentroot">DocumentRoot</a></code>
6d9c7d0283713aa8ae15fef7e9bfe2c7bfa73872nd make up the basic document tree which will be visible from the
7db9f691a00ead175b03335457ca296a33ddf31bnd web.</p>
3577f1d38e53397f6b431c02011f875316b2f070nd
d09f538b07aa757f9e6290bd54d28fc1605725a9nd <p>Apache is also capable of <a href="vhosts/">Virtual
d09f538b07aa757f9e6290bd54d28fc1605725a9nd Hosting</a>, where the server receives requests for more than one
d09f538b07aa757f9e6290bd54d28fc1605725a9nd host. In this case, a different <code class="directive"><a href="/mod/core.html#documentroot">DocumentRoot</a></code> can be specified for each
d09f538b07aa757f9e6290bd54d28fc1605725a9nd virtual host, or alternatively, the directives provided by the
d09f538b07aa757f9e6290bd54d28fc1605725a9nd module <code class="module"><a href="/mod/mod_vhost_alias.html">mod_vhost_alias</a></code> can
079a689f4bf2a6a0d512826062962c7d9fb1091fpoirier be used to dynamically determine the appropriate place from which
1c43f6d6b548071e453eba0f72b2b7b0eb486124trawick to serve content based on the requested IP address or
1c43f6d6b548071e453eba0f72b2b7b0eb486124trawick hostname.</p>
1c43f6d6b548071e453eba0f72b2b7b0eb486124trawick</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div><div class="section"><h2><a name="outside" id="outside">Files Outside the DocumentRoot</a></h2>
1c43f6d6b548071e453eba0f72b2b7b0eb486124trawick
1c43f6d6b548071e453eba0f72b2b7b0eb486124trawick <p>There are frequently circumstances where it is necessary to
1c43f6d6b548071e453eba0f72b2b7b0eb486124trawick allow web access to parts of the filesystem that are not strictly
1c43f6d6b548071e453eba0f72b2b7b0eb486124trawick underneath the <code class="directive"><a href="/mod/core.html#documentroot">DocumentRoot</a></code>. Apache offers several
d09f538b07aa757f9e6290bd54d28fc1605725a9nd different ways to accomplish this. On Unix systems, symbolic links
d09f538b07aa757f9e6290bd54d28fc1605725a9nd can bring other parts of the filesystem under the <code class="directive"><a href="/mod/core.html#documentroot">DocumentRoot</a></code>. For security reasons,
d09f538b07aa757f9e6290bd54d28fc1605725a9nd Apache will follow symbolic links only if the <code class="directive"><a href="/mod/core.html#options">Options</a></code> setting for the relevant
1c43f6d6b548071e453eba0f72b2b7b0eb486124trawick directory includes <code>FollowSymLinks</code> or
1c43f6d6b548071e453eba0f72b2b7b0eb486124trawick <code>SymLinksIfOwnerMatch</code>.</p>
1c43f6d6b548071e453eba0f72b2b7b0eb486124trawick
d09f538b07aa757f9e6290bd54d28fc1605725a9nd <p>Alternatively, the <code class="directive"><a href="/mod/mod_alias.html#alias">Alias</a></code> directive will map any part
d09f538b07aa757f9e6290bd54d28fc1605725a9nd of the filesystem into the web space. For example, with</p>
d09f538b07aa757f9e6290bd54d28fc1605725a9nd
d09f538b07aa757f9e6290bd54d28fc1605725a9nd<div class="example"><p><code>Alias /docs /var/web</code></p></div>
d09f538b07aa757f9e6290bd54d28fc1605725a9nd
d09f538b07aa757f9e6290bd54d28fc1605725a9nd <p>the URL <code>http://www.example.com/docs/dir/file.html</code>
d09f538b07aa757f9e6290bd54d28fc1605725a9nd will be served from <code>/var/web/dir/file.html</code>. The
d09f538b07aa757f9e6290bd54d28fc1605725a9nd <code class="directive"><a href="/mod/mod_alias.html#scriptalias">ScriptAlias</a></code> directive
d09f538b07aa757f9e6290bd54d28fc1605725a9nd works the same way, with the additional effect that all content
d09f538b07aa757f9e6290bd54d28fc1605725a9nd located at the target path is treated as CGI scripts.</p>
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe <p>For situations where you require additional flexibility, you
d09f538b07aa757f9e6290bd54d28fc1605725a9nd can use the <code class="directive"><a href="/mod/mod_alias.html#aliasmatch">AliasMatch</a></code> and
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe <code class="directive"><a href="/mod/mod_alias.html#scriptaliasmatch">ScriptAliasMatch</a></code>
d09f538b07aa757f9e6290bd54d28fc1605725a9nd directives to do powerful regular-expression based matching and
d09f538b07aa757f9e6290bd54d28fc1605725a9nd substitution. For example,</p>
10eb146f9b1de4ae36f9888e81bab58639fe958ewrowe
10eb146f9b1de4ae36f9888e81bab58639fe958ewrowe<div class="example"><p><code>ScriptAliasMatch ^/~([a-zA-Z0-9]*)/cgi-bin/(.*)
10eb146f9b1de4ae36f9888e81bab58639fe958ewrowe /home/$1/cgi-bin/$2</code></p></div>
10eb146f9b1de4ae36f9888e81bab58639fe958ewrowe
d09f538b07aa757f9e6290bd54d28fc1605725a9nd <p>will map a request to
d09f538b07aa757f9e6290bd54d28fc1605725a9nd <code>http://example.com/~user/cgi-bin/script.cgi</code> to the
d09f538b07aa757f9e6290bd54d28fc1605725a9nd path <code>/home/user/cgi-bin/script.cgi</code> and will treat
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe the resulting file as a CGI script.</p>
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div><div class="section"><h2><a name="user" id="user">User Directories</a></h2>
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe <p>Traditionally on Unix systems, the home directory of a
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe particular <em>user</em> can be referred to as
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe <code>~user/</code>. The module <code class="module"><a href="/mod/mod_userdir.html">mod_userdir</a></code>
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe extends this idea to the web by allowing files under each user's
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe home directory to be accessed using URLs such as the
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe following.</p>
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe<div class="example"><p><code>http://www.example.com/~user/file.html</code></p></div>
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe <p>For security reasons, it is inappropriate to give direct
10eb146f9b1de4ae36f9888e81bab58639fe958ewrowe access to a user's home directory from the web. Therefore, the
d09f538b07aa757f9e6290bd54d28fc1605725a9nd <code class="directive"><a href="/mod/mod_userdir.html#userdir">UserDir</a></code> directive
d09f538b07aa757f9e6290bd54d28fc1605725a9nd specifies a directory underneath the user's home directory
d09f538b07aa757f9e6290bd54d28fc1605725a9nd where web files are located. Using the default setting of
d09f538b07aa757f9e6290bd54d28fc1605725a9nd <code>Userdir public_html</code>, the above URL maps to a file
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe at a directory like
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe <code>/home/user/public_html/file.html</code> where
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe <code>/home/user/</code> is the user's home directory as
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe specified in <code>/etc/passwd</code>.</p>
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe <p>There are also several other forms of the
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe <code>Userdir</code> directive which you can use on systems
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe where <code>/etc/passwd</code> does not contain the location of
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe the home directory.</p>
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe <p>Some people find the "~" symbol (which is often encoded on the
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe web as <code>%7e</code>) to be awkward and prefer to use an
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe alternate string to represent user directories. This functionality
d09f538b07aa757f9e6290bd54d28fc1605725a9nd is not supported by mod_userdir. However, if users' home
d09f538b07aa757f9e6290bd54d28fc1605725a9nd directories are structured in a regular way, then it is possible
d09f538b07aa757f9e6290bd54d28fc1605725a9nd to use the <code class="directive"><a href="/mod/mod_alias.html#aliasmatch">AliasMatch</a></code>
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe directive to achieve the desired effect. For example, to make
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe <code>http://www.example.com/upages/user/file.html</code> map to
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe <code>/home/user/public_html/file.html</code>, use the following
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe <code>AliasMatch</code> directive:</p>
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe<div class="example"><p><code>AliasMatch ^/upages/([a-zA-Z0-9]*)/?(.*)
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe /home/$1/public_html/$2</code></p></div>
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div><div class="section"><h2><a name="redirect" id="redirect">URL Redirection</a></h2>
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jim
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe <p>The configuration directives discussed in the above sections
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe tell Apache to get content from a specific place in the filesystem
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe and return it to the client. Sometimes, it is desirable instead to
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe inform the client that the requested content is located at a
d09f538b07aa757f9e6290bd54d28fc1605725a9nd different URL, and instruct the client to make a new request with
d09f538b07aa757f9e6290bd54d28fc1605725a9nd the new URL. This is called <em>redirection</em> and is
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe implemented by the <code class="directive"><a href="/mod/mod_alias.html#redirect">Redirect</a></code> directive. For example, if
d09f538b07aa757f9e6290bd54d28fc1605725a9nd the contents of the directory <code>/foo/</code> under the
d09f538b07aa757f9e6290bd54d28fc1605725a9nd <code class="directive"><a href="/mod/mod_alias.html#documentroot">DocumentRoot</a></code> are moved
d09f538b07aa757f9e6290bd54d28fc1605725a9nd to the new directory <code>/bar/</code>, you can instruct clients
d09f538b07aa757f9e6290bd54d28fc1605725a9nd to request the content at the new location as follows:</p>
d09f538b07aa757f9e6290bd54d28fc1605725a9nd
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe<div class="example"><p><code>Redirect permanent /foo/
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe http://www.example.com/bar/</code></p></div>
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe <p>This will redirect any URL-Path starting in
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jim <code>/foo/</code> to the same URL path on the
d09f538b07aa757f9e6290bd54d28fc1605725a9nd <code>www.example.com</code> server with <code>/bar/</code>
d7311de3d9c9938d10b36f37406d6968d1f31564wrowe substituted for <code>/foo/</code>. You can redirect clients to
d7311de3d9c9938d10b36f37406d6968d1f31564wrowe any server, not only the origin server.</p>
10eb146f9b1de4ae36f9888e81bab58639fe958ewrowe
10eb146f9b1de4ae36f9888e81bab58639fe958ewrowe <p>Apache also provides a <code class="directive"><a href="/mod/mod_alias.html#redirectmatch">RedirectMatch</a></code> directive for more
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe complicated rewriting problems. For example, to redirect requests
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe for the site home page to a different site, but leave all other
d09f538b07aa757f9e6290bd54d28fc1605725a9nd requests alone, use the following configuration:</p>
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe<div class="example"><p><code>RedirectMatch permanent ^/$
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe http://www.example.com/startpage.html</code></p></div>
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe
d09f538b07aa757f9e6290bd54d28fc1605725a9nd <p>Alternatively, to temporarily redirect all pages on a site
10eb146f9b1de4ae36f9888e81bab58639fe958ewrowe to one particular page, use the following:</p>
10eb146f9b1de4ae36f9888e81bab58639fe958ewrowe
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe<div class="example"><p><code>RedirectMatch temp .*
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe http://www.example.com/startpage.html</code></p></div>
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div><div class="section"><h2><a name="proxy" id="proxy">Reverse Proxy</a></h2>
10eb146f9b1de4ae36f9888e81bab58639fe958ewrowe
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe<p>Apache also allows you to bring remote documents into the URL space
81f8f47e9778b26ad98d4e88defe8879713171d9wroweof the local server. This technique is called <em>reverse
81f8f47e9778b26ad98d4e88defe8879713171d9wroweproxying</em> because the web server acts like a proxy server by
81f8f47e9778b26ad98d4e88defe8879713171d9wrowefetching the documents from a remote server and returning them to the
d09f538b07aa757f9e6290bd54d28fc1605725a9ndclient. It is different from normal proxying because, to the client,
d7311de3d9c9938d10b36f37406d6968d1f31564wroweit appears the documents originate at the reverse proxy server.</p>
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jim
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jim<p>In the following example, when clients request documents under the
d7311de3d9c9938d10b36f37406d6968d1f31564wrowe<code>/foo/</code> directory, the server fetches those documents from
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jimthe <code>/bar/</code> directory on <code>internal.example.com</code>
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jimand returns them to the client as if they were from the local
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jimserver.</p>
d7311de3d9c9938d10b36f37406d6968d1f31564wrowe
d7311de3d9c9938d10b36f37406d6968d1f31564wrowe<div class="example"><p><code>
d7311de3d9c9938d10b36f37406d6968d1f31564wroweProxyPass /foo/ http://internal.example.com/bar/<br />
d09f538b07aa757f9e6290bd54d28fc1605725a9ndProxyPassReverse /foo/ http://internal.example.com/bar/
d09f538b07aa757f9e6290bd54d28fc1605725a9nd</code></p></div>
10eb146f9b1de4ae36f9888e81bab58639fe958ewrowe
10eb146f9b1de4ae36f9888e81bab58639fe958ewrowe<p>The <code class="directive"><a href="/mod/mod_proxy.html#proxypass">ProxyPass</a></code> configures
81f8f47e9778b26ad98d4e88defe8879713171d9wrowethe server to fetch the appropriate documents, while the
10eb146f9b1de4ae36f9888e81bab58639fe958ewrowe<code class="directive"><a href="/mod/mod_proxy.html#proxypassreverse">ProxyPassReverse</a></code>
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jimdirective rewrites redirects originating at
10eb146f9b1de4ae36f9888e81bab58639fe958ewrowe<code>internal.examle.com</code> so that they target the appropriate
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jimdirectory on the local server. It is important to note, however, that
10eb146f9b1de4ae36f9888e81bab58639fe958ewrowelinks inside the documents will not be rewritten. So any absolute
10eb146f9b1de4ae36f9888e81bab58639fe958ewrowelinks on <code>internal.example.com</code> will result in the client
10eb146f9b1de4ae36f9888e81bab58639fe958ewrowebreaking out of the proxy server and requesting directly from
10eb146f9b1de4ae36f9888e81bab58639fe958ewrowe<code>internal.example.com</code>.</p>
10eb146f9b1de4ae36f9888e81bab58639fe958ewrowe</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div><div class="section"><h2><a name="rewrite" id="rewrite">Rewriting Engine</a></h2>
10eb146f9b1de4ae36f9888e81bab58639fe958ewrowe
10eb146f9b1de4ae36f9888e81bab58639fe958ewrowe <p>When even more powerful substitution is required, the rewriting
10eb146f9b1de4ae36f9888e81bab58639fe958ewrowe engine provided by <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code>
d09f538b07aa757f9e6290bd54d28fc1605725a9nd can be useful. The directives provided by this module use
d09f538b07aa757f9e6290bd54d28fc1605725a9nd characteristics of the request such as browser type or source IP
d09f538b07aa757f9e6290bd54d28fc1605725a9nd address in deciding from where to serve content. In addition,
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe mod_rewrite can use external database files or programs to
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe determine how to handle a request. The rewriting engine is capable
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe of performing all three types of mappings discussed above:
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe internal redirects (aliases), external redirects, and proxying.
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe Many practical examples employing mod_rewrite are discussed in the
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe <a href="misc/rewriteguide.html">URL Rewriting Guide</a>.</p>
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div><div class="section"><h2><a name="notfound" id="notfound">File Not Found</a></h2>
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jim
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe <p>Inevitably, URLs will be requested for which no matching
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe file can be found in the filesystem. This can happen for
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe several reasons. In some cases, it can be a result of moving
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe documents from one location to another. In this case, it is
d09f538b07aa757f9e6290bd54d28fc1605725a9nd best to use <a href="#redirect">URL redirection</a> to inform
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jim clients of the new location of the resource. In this way, you
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jim can assure that old bookmarks and links will continue to work,
10eb146f9b1de4ae36f9888e81bab58639fe958ewrowe even though the resource is at a new location.</p>
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jim
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe <p>Another common cause of "File Not Found" errors is
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jim accidental mistyping of URLs, either directly in the browser,
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe or in HTML links. Apache provides the module
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe <code class="module"><a href="/mod/mod_speling.html">mod_speling</a></code> (sic) to help with
d09f538b07aa757f9e6290bd54d28fc1605725a9nd this problem. When this module is activated, it will intercept
d09f538b07aa757f9e6290bd54d28fc1605725a9nd "File Not Found" errors and look for a resource with a similar
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jim filename. If one such file is found, mod_speling will send an
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe HTTP redirect to the client informing it of the correct
10eb146f9b1de4ae36f9888e81bab58639fe958ewrowe location. If several "close" files are found, a list of
10eb146f9b1de4ae36f9888e81bab58639fe958ewrowe available alternatives will be presented to the client.</p>
d09f538b07aa757f9e6290bd54d28fc1605725a9nd
d09f538b07aa757f9e6290bd54d28fc1605725a9nd <p>An especially useful feature of mod_speling, is that it will
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe compare filenames without respect to case. This can help
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe systems where users are unaware of the case-sensitive nature of
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe URLs and the unix filesystem. But using mod_speling for
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe anything more than the occasional URL correction can place
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe additional load on the server, since each "incorrect" request
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jim is followed by a URL redirection and a new request from the
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe client.</p>
d09f538b07aa757f9e6290bd54d28fc1605725a9nd
d09f538b07aa757f9e6290bd54d28fc1605725a9nd <p>If all attempts to locate the content fail, Apache returns
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe an error page with HTTP status code 404 (file not found). The
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe appearance of this page is controlled with the
2f83bdeb8f4a4f370e26edf99666e7965c58de22poirier <code class="directive"><a href="/mod/core.html#errordocument">ErrorDocument</a></code> directive
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe and can be customized in a flexible manner as discussed in the
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe <a href="custom-error.html">Custom error responses</a> and <a href="misc/custom_errordocs.html">International Server Error
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe Responses</a> documents.</p>
81f8f47e9778b26ad98d4e88defe8879713171d9wrowe</div></div><div id="footer"><p class="apache">Maintained by the <a href="http://httpd.apache.org/docs-project/">Apache HTTP Server Documentation Project</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>