📄 urlmapping.html.en
字号:
<code>AliasMatch</code> directive:</p>
<div class="example"><p><code>AliasMatch ^/upages/([a-zA-Z0-9]+)/?(.*)
/home/$1/public_html/$2</code></p></div>
</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>
<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
<code class="directive"><a href="./mod/core.html#documentroot">DocumentRoot</a></code> are moved
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/
http://www.example.com/bar/</code></p></div>
<p>This will redirect any URL-Path starting in
<code>/foo/</code> to the same URL path on the
<code>www.example.com</code> server with <code>/bar/</code>
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 ^/$
http://www.example.com/startpage.html</code></p></div>
<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 .*
http://othersite.example.com/startpage.html</code></p></div>
</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>
<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
the <code>/bar/</code> directory on <code>internal.example.com</code>
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/
</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
<code class="directive"><a href="./mod/mod_proxy.html#proxypassreverse">ProxyPassReverse</a></code>
directive rewrites redirects originating at
<code>internal.example.com</code> so that they target the appropriate
directory on the local server. It is important to note, however, that
links inside the documents will not be rewritten. So any absolute
links on <code>internal.example.com</code> will result in the client
breaking out of the proxy server and requesting directly from
<code>internal.example.com</code>.</p>
</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>
<p>When even more powerful substitution is required, the rewriting
engine provided by <code class="module"><a href="./mod/mod_rewrite.html">mod_rewrite</a></code>
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
<a href="misc/rewriteguide.html">URL Rewriting Guide</a>.</p>
</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>
<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
<code class="module"><a href="./mod/mod_speling.html">mod_speling</a></code> (sic) to help with
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
<code class="directive"><a href="./mod/core.html#errordocument">ErrorDocument</a></code> directive
and can be customized in a flexible manner as discussed in the
<a href="custom-error.html">Custom error responses</a> and <a href="misc/custom_errordocs.html">International Server Error
Responses</a> documents.</p>
</div></div>
<div class="bottomlang">
<p><span>Available Languages: </span><a href="./en/urlmapping.html" title="English"> en </a> |
<a href="./ja/urlmapping.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> |
<a href="./ko/urlmapping.html" hreflang="ko" rel="alternate" title="Korean"> ko </a></p>
</div><div id="footer">
<p class="apache">Copyright 2006 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>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -