mirror of
https://github.com/apache/httpd.git
synced 2025-04-18 22:24:07 +03:00
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1915460 13f79535-47bb-0310-9956-ffa450edef68
703 lines
42 KiB
XML
703 lines
42 KiB
XML
<?xml version="1.0" encoding="UTF-8"?>
|
||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
|
||
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
|
||
<!--
|
||
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|
||
This file is generated from xml source: DO NOT EDIT
|
||
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|
||
-->
|
||
<title>mod_alias - Apache HTTP Server Version 2.5</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" />
|
||
<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" />
|
||
<script src="../style/scripts/prettify.min.js" type="text/javascript">
|
||
</script>
|
||
|
||
<link href="../images/favicon.ico" rel="shortcut icon" /></head>
|
||
<body>
|
||
<div id="page-header">
|
||
<p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/quickreference.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>
|
||
<p class="apache">Apache HTTP Server Version 2.5</p>
|
||
<img alt="" src="../images/feather.png" /></div>
|
||
<div class="up"><a href="./"><img title="<-" alt="<-" src="../images/left.gif" /></a></div>
|
||
<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.5</a> > <a href="./">Modules</a></div>
|
||
<div id="page-content">
|
||
<div id="preamble"><h1>Apache Module mod_alias</h1>
|
||
<div class="toplang">
|
||
<p><span>Available Languages: </span><a href="../en/mod/mod_alias.html" title="English"> en </a> |
|
||
<a href="../es/mod/mod_alias.html" hreflang="es" rel="alternate" title="Español"> es </a> |
|
||
<a href="../fr/mod/mod_alias.html" hreflang="fr" rel="alternate" title="Français"> fr </a> |
|
||
<a href="../ja/mod/mod_alias.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> |
|
||
<a href="../ko/mod/mod_alias.html" hreflang="ko" rel="alternate" title="Korean"> ko </a> |
|
||
<a href="../tr/mod/mod_alias.html" hreflang="tr" rel="alternate" title="Türkçe"> tr </a></p>
|
||
</div>
|
||
<table class="module"><tr><th><a href="module-dict.html#Description">Description:</a></th><td>Provides for mapping different parts of the host
|
||
filesystem in the document tree and for URL redirection</td></tr>
|
||
<tr><th><a href="module-dict.html#Status">Status:</a></th><td>Base</td></tr>
|
||
<tr><th><a href="module-dict.html#ModuleIdentifier">Module Identifier:</a></th><td>alias_module</td></tr>
|
||
<tr><th><a href="module-dict.html#SourceFile">Source File:</a></th><td>mod_alias.c</td></tr></table>
|
||
<h3>Summary</h3>
|
||
|
||
<p>The directives contained in this module allow for manipulation
|
||
and control of URLs as requests arrive at the server. The
|
||
<code class="directive"><a href="#alias">Alias</a></code> and <code class="directive"><a href="#scriptalias">ScriptAlias</a></code> directives are used to
|
||
map between URLs and filesystem paths. This allows for content
|
||
which is not directly under the <code class="directive"><a href="../mod/core.html#documentroot">DocumentRoot</a></code> served as part of the web
|
||
document tree. The <code class="directive"><a href="#scriptalias">ScriptAlias</a></code> directive has the
|
||
additional effect of marking the target directory as containing
|
||
only CGI scripts.</p>
|
||
|
||
<p>The <code class="directive"><a href="#redirect">Redirect</a></code>
|
||
directives are used to instruct clients to make a new request with
|
||
a different URL. They are often used when a resource has moved to
|
||
a new location.</p>
|
||
|
||
<p>When the <code class="directive"><a href="#alias">Alias</a></code>,
|
||
<code class="directive"><a href="#scriptalias">ScriptAlias</a></code> and
|
||
<code class="directive"><a href="#redirect">Redirect</a></code> directives are used
|
||
within a <code class="directive"><a href="../mod/core.html#location"><Location></a></code>
|
||
or <code class="directive"><a href="../mod/core.html#locationmatch"><LocationMatch></a></code>
|
||
section, <a href="../expr.html">expression syntax</a> can be used
|
||
to manipulate the destination path or URL.
|
||
</p>
|
||
|
||
<p><code class="module"><a href="../mod/mod_alias.html">mod_alias</a></code> is designed to handle simple URL
|
||
manipulation tasks. For more complicated tasks such as
|
||
manipulating the query string, use the tools provided by
|
||
<code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code>.</p>
|
||
|
||
</div>
|
||
<div id="quickview"><h3>Topics</h3>
|
||
<ul id="topics">
|
||
<li><img alt="" src="../images/down.gif" /> <a href="#order">Order of Processing</a></li>
|
||
</ul><h3 class="directives">Directives</h3>
|
||
<ul id="toc">
|
||
<li><img alt="" src="../images/down.gif" /> <a href="#alias">Alias</a></li>
|
||
<li><img alt="" src="../images/down.gif" /> <a href="#aliasmatch">AliasMatch</a></li>
|
||
<li><img alt="" src="../images/down.gif" /> <a href="#aliaspreservepath">AliasPreservePath</a></li>
|
||
<li><img alt="" src="../images/down.gif" /> <a href="#redirect">Redirect</a></li>
|
||
<li><img alt="" src="../images/down.gif" /> <a href="#redirectmatch">RedirectMatch</a></li>
|
||
<li><img alt="" src="../images/down.gif" /> <a href="#redirectpermanent">RedirectPermanent</a></li>
|
||
<li><img alt="" src="../images/down.gif" /> <a href="#redirectrelative">RedirectRelative</a></li>
|
||
<li><img alt="" src="../images/down.gif" /> <a href="#redirecttemp">RedirectTemp</a></li>
|
||
<li><img alt="" src="../images/down.gif" /> <a href="#scriptalias">ScriptAlias</a></li>
|
||
<li><img alt="" src="../images/down.gif" /> <a href="#scriptaliasmatch">ScriptAliasMatch</a></li>
|
||
</ul>
|
||
<h3>Bugfix checklist</h3><ul class="seealso"><li><a href="https://www.apache.org/dist/httpd/CHANGES_2.4">httpd changelog</a></li><li><a href="https://bz.apache.org/bugzilla/buglist.cgi?bug_status=__open__&list_id=144532&product=Apache%20httpd-2&query_format=specific&order=changeddate%20DESC%2Cpriority%2Cbug_severity&component=mod_alias">Known issues</a></li><li><a href="https://bz.apache.org/bugzilla/enter_bug.cgi?product=Apache%20httpd-2&component=mod_alias">Report a bug</a></li></ul><h3>See also</h3>
|
||
<ul class="seealso">
|
||
<li><code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code></li>
|
||
<li><a href="../urlmapping.html">Mapping URLs to the filesystem</a></li>
|
||
<li><a href="#comments_section">Comments</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="order" id="order">Order of Processing</a> <a title="Permanent link" href="#order" class="permalink">¶</a></h2>
|
||
|
||
<p>Aliases and Redirects occurring in different contexts are processed
|
||
like other directives according to standard <a href="../sections.html#mergin">merging rules</a>. But when multiple
|
||
Aliases or Redirects occur in the same context (for example, in the
|
||
same <code class="directive"><a href="../mod/core.html#virtualhost"><VirtualHost></a></code>
|
||
section) they are processed in a particular order.</p>
|
||
|
||
<p>First, all Redirects are processed before Aliases are processed,
|
||
and therefore a request that matches a <code class="directive"><a href="#redirect">Redirect</a></code> or <code class="directive"><a href="#redirectmatch">RedirectMatch</a></code> will never have Aliases
|
||
applied. Second, the Aliases and Redirects are processed in the order
|
||
they appear in the configuration files, with the first match taking
|
||
precedence.</p>
|
||
|
||
<p>For this reason, when two or more of these directives apply to the
|
||
same sub-path, you must list the most specific path first in order for
|
||
all the directives to have an effect. For example, the following
|
||
configuration will work as expected:</p>
|
||
|
||
<pre class="prettyprint lang-config">Alias "/foo/bar" "/baz"
|
||
Alias "/foo" "/gaq"</pre>
|
||
|
||
|
||
<p>But if the above two directives were reversed in order, the
|
||
<code>/foo</code> <code class="directive"><a href="#alias">Alias</a></code>
|
||
would always match before the <code>/foo/bar</code> <code class="directive"><a href="#alias">Alias</a></code>, so the latter directive would be
|
||
ignored.</p>
|
||
|
||
<p>When the <code class="directive"><a href="#alias">Alias</a></code>,
|
||
<code class="directive"><a href="#scriptalias">ScriptAlias</a></code> and
|
||
<code class="directive"><a href="#redirect">Redirect</a></code> directives are used
|
||
within a <code class="directive"><a href="../mod/core.html#location"><Location></a></code>
|
||
or <code class="directive"><a href="../mod/core.html#locationmatch"><LocationMatch></a></code>
|
||
section, these directives will take precedence over any globally
|
||
defined <code class="directive"><a href="#alias">Alias</a></code>,
|
||
<code class="directive"><a href="#scriptalias">ScriptAlias</a></code> and
|
||
<code class="directive"><a href="#redirect">Redirect</a></code> directives.</p>
|
||
|
||
</div>
|
||
<div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
|
||
<div class="directive-section"><h2><a name="Alias" id="Alias">Alias</a> <a name="alias" id="alias">Directive</a> <a title="Permanent link" href="#alias" class="permalink">¶</a></h2>
|
||
<table class="directive">
|
||
<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Maps URLs to filesystem locations</td></tr>
|
||
<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>Alias [<var>URL-path</var>]
|
||
<var>file-path</var>|<var>directory-path</var></code></td></tr>
|
||
<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory</td></tr>
|
||
<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
|
||
<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_alias</td></tr>
|
||
</table>
|
||
|
||
<p>The <code class="directive">Alias</code> directive allows documents to
|
||
be stored in the local filesystem other than under the
|
||
<code class="directive"><a href="../mod/core.html#documentroot">DocumentRoot</a></code>. URLs with a
|
||
(%-decoded) path beginning with <var>URL-path</var> will be mapped
|
||
to local files beginning with <var>directory-path</var>. The
|
||
<var>URL-path</var> is case-sensitive, even on case-insensitive
|
||
file systems.</p>
|
||
|
||
<pre class="prettyprint lang-config">Alias "/image" "/ftp/pub/image"</pre>
|
||
|
||
|
||
<p>A request for <code>http://example.com/image/foo.gif</code> would cause
|
||
the server to return the file <code>/ftp/pub/image/foo.gif</code>. Only
|
||
complete path segments are matched, so the above alias would not match a
|
||
request for <code>http://example.com/imagefoo.gif</code>. For more complex
|
||
matching using regular expressions, see the <code class="directive"><a href="#aliasmatch">AliasMatch</a></code> directive.</p>
|
||
|
||
<p>Note that if you include a trailing / on the
|
||
<var>URL-path</var> then the server will require a trailing / in
|
||
order to expand the alias. That is, if you use</p>
|
||
|
||
<pre class="prettyprint lang-config">Alias "/icons/" "/usr/local/apache/icons/"</pre>
|
||
|
||
|
||
<p>then the URL <code>/icons</code> will not be aliased, as it lacks
|
||
that trailing /. Likewise, if you omit the slash on the
|
||
<var>URL-path</var> then you must also omit it from the
|
||
<var>file-path</var>.</p>
|
||
|
||
<p>Note that you may need to specify additional <code class="directive"><a href="../mod/core.html#directory"><Directory></a></code> sections which
|
||
cover the <em>destination</em> of aliases. Aliasing occurs before
|
||
<code class="directive"><a href="../mod/core.html#directory"><Directory></a></code> sections
|
||
are checked, so only the destination of aliases are affected.
|
||
(Note however <code class="directive"><a href="../mod/core.html#location"><Location></a></code>
|
||
sections are run through once before aliases are performed, so
|
||
they will apply.)</p>
|
||
|
||
<p>In particular, if you are creating an <code>Alias</code> to a
|
||
directory outside of your <code class="directive"><a href="../mod/core.html#documentroot">DocumentRoot</a></code>, you may need to explicitly
|
||
permit access to the target directory.</p>
|
||
|
||
<pre class="prettyprint lang-config">Alias "/image" "/ftp/pub/image"
|
||
<Directory "/ftp/pub/image">
|
||
Require all granted
|
||
</Directory></pre>
|
||
|
||
|
||
<p>Any number slashes in the <var>URL-path</var> parameter
|
||
matches any number of slashes in the requested URL-path.</p>
|
||
|
||
<p>If the <code class="directive">Alias</code> directive is used within a
|
||
<code class="directive"><a href="../mod/core.html#location"><Location></a></code>
|
||
or <code class="directive"><a href="../mod/core.html#locationmatch"><LocationMatch></a></code>
|
||
section the URL-path is omitted, and the file-path is interpreted
|
||
using <a href="../expr.html">expression syntax</a>.<br />
|
||
This syntax is available in Apache 2.4.19 and later.</p>
|
||
|
||
<pre class="prettyprint lang-config"><Location "/image">
|
||
Alias "/ftp/pub/image"
|
||
</Location>
|
||
<LocationMatch "/error/(?<NUMBER>[0-9]+)">
|
||
Alias "/usr/local/apache/errors/%{env:MATCH_NUMBER}.html"
|
||
</LocationMatch></pre>
|
||
|
||
|
||
<p>Note that when the <code class="directive">AliasPreservePath</code>
|
||
directive is on, the full path is mapped to the destination. When
|
||
the directive is off, all URLs are mapped to the single target
|
||
URL.</p>
|
||
|
||
<pre class="prettyprint lang-config"># /files/foo and /files/bar mapped to /ftp/pub/files/foo and /ftp/pub/files/bar
|
||
<Location "/files">
|
||
AliasPreservePath on
|
||
Alias "/ftp/pub/files"
|
||
</Location>
|
||
# /errors/foo and /errors/bar mapped to /var/www/errors.html
|
||
<Location "/errors">
|
||
AliasPreservePath off
|
||
Alias "/var/www/errors.html"
|
||
</Location></pre>
|
||
|
||
|
||
|
||
</div>
|
||
<div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
|
||
<div class="directive-section"><h2><a name="AliasMatch" id="AliasMatch">AliasMatch</a> <a name="aliasmatch" id="aliasmatch">Directive</a> <a title="Permanent link" href="#aliasmatch" class="permalink">¶</a></h2>
|
||
<table class="directive">
|
||
<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Maps URLs to filesystem locations using regular
|
||
expressions</td></tr>
|
||
<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>AliasMatch <var>regex</var>
|
||
<var>file-path</var>|<var>directory-path</var></code></td></tr>
|
||
<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
|
||
<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
|
||
<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_alias</td></tr>
|
||
</table>
|
||
<p>This directive is equivalent to <code class="directive"><a href="#alias">Alias</a></code>, but makes use of
|
||
<a class="glossarylink" href="../glossary.html#regex" title="see glossary">regular expressions</a>,
|
||
instead of simple prefix matching. The
|
||
supplied regular expression is matched against the URL-path, and
|
||
if it matches, the server will substitute any parenthesized
|
||
matches into the given string and use it as a filename. For
|
||
example, to activate the <code>/icons</code> directory, one might
|
||
use:</p>
|
||
|
||
<pre class="prettyprint lang-config">AliasMatch "^/icons(/|$)(.*)" "/usr/local/apache/icons$1$2"</pre>
|
||
|
||
|
||
<p>The full range of <a class="glossarylink" href="../glossary.html#regex" title="see glossary">regular expression</a>
|
||
power is available. For example,
|
||
it is possible to construct an alias with case-insensitive
|
||
matching of the URL-path:</p>
|
||
|
||
<pre class="prettyprint lang-config">AliasMatch "(?i)^/image(.*)" "/ftp/pub/image$1"</pre>
|
||
|
||
|
||
<p>One subtle difference
|
||
between <code class="directive"><a href="#alias">Alias</a></code>
|
||
and <code class="directive">AliasMatch</code> is
|
||
that <code class="directive"><a href="#alias">Alias</a></code> will
|
||
automatically copy any additional part of the URI, past the part
|
||
that matched, onto the end of the file path on the right side,
|
||
while <code class="directive">AliasMatch</code> will
|
||
not. This means that in almost all cases, you will want the
|
||
regular expression to match the entire request URI from beginning
|
||
to end, and to use substitution on the right side.</p>
|
||
|
||
<p>In other words, just changing
|
||
<code class="directive"><a href="#alias">Alias</a></code> to
|
||
<code class="directive">AliasMatch</code> will not
|
||
have the same effect. At a minimum, you need to
|
||
add <code>^</code> to the beginning of the regular expression
|
||
and add <code>(.*)$</code> to the end, and add <code>$1</code> to
|
||
the end of the replacement.</p>
|
||
|
||
<p>For example, suppose you want to replace this with AliasMatch:</p>
|
||
|
||
<pre class="prettyprint lang-config">Alias "/image/" "/ftp/pub/image/"</pre>
|
||
|
||
|
||
<p>This is NOT equivalent - don't do this! This will send all
|
||
requests that have /image/ anywhere in them to /ftp/pub/image/:</p>
|
||
|
||
<pre class="prettyprint lang-config">AliasMatch "/image/" "/ftp/pub/image/"</pre>
|
||
|
||
|
||
<p>This is what you need to get the same effect:</p>
|
||
|
||
<pre class="prettyprint lang-config">AliasMatch "^/image/(.*)$" "/ftp/pub/image/$1"</pre>
|
||
|
||
|
||
<p>Of course, there's no point in
|
||
using <code class="directive">AliasMatch</code>
|
||
where <code class="directive"><a href="#alias">Alias</a></code> would
|
||
work. <code class="directive">AliasMatch</code> lets
|
||
you do more complicated things. For example, you could
|
||
serve different kinds of files from different directories:</p>
|
||
|
||
<pre class="prettyprint lang-config">AliasMatch "^/image/(.*)\.jpg$" "/files/jpg.images/$1.jpg"
|
||
AliasMatch "^/image/(.*)\.gif$" "/files/gif.images/$1.gif"</pre>
|
||
|
||
|
||
<p>Multiple leading slashes in the requested URL are discarded
|
||
by the server before directives from this module compares
|
||
against the requested URL-path.
|
||
</p>
|
||
|
||
|
||
</div>
|
||
<div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
|
||
<div class="directive-section"><h2><a name="AliasPreservePath" id="AliasPreservePath">AliasPreservePath</a> <a name="aliaspreservepath" id="aliaspreservepath">Directive</a> <a title="Permanent link" href="#aliaspreservepath" class="permalink">¶</a></h2>
|
||
<table class="directive">
|
||
<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Map the full path after the alias in a location.</td></tr>
|
||
<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>AliasPreservePath OFF|ON</code></td></tr>
|
||
<tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>AliasPreservePath OFF</code></td></tr>
|
||
<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory</td></tr>
|
||
<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
|
||
<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_alias</td></tr>
|
||
<tr><th><a href="directive-dict.html#Compatibility">Compatibility:</a></th><td>2.5.1 and later</td></tr>
|
||
</table>
|
||
<p>When using the two parameter version of the
|
||
<code class="directive">Alias</code> directive, the full path after the alias
|
||
is preserved. When using the one parameter version of the
|
||
<code class="directive">Alias</code> directive inside a
|
||
<code class="directive">Location</code> directive, the full path is dropped,
|
||
and all URLs are mapped to the target expression.</p>
|
||
|
||
<p>To make the one parameter version of the
|
||
<code class="directive">Alias</code> directive preserve paths in the same way
|
||
that the two parameter version of the <code class="directive">Alias</code>
|
||
directive, enable this setting.</p>
|
||
|
||
|
||
</div>
|
||
<div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
|
||
<div class="directive-section"><h2><a name="Redirect" id="Redirect">Redirect</a> <a name="redirect" id="redirect">Directive</a> <a title="Permanent link" href="#redirect" class="permalink">¶</a></h2>
|
||
<table class="directive">
|
||
<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sends an external redirect asking the client to fetch
|
||
a different URL</td></tr>
|
||
<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>Redirect [<var>status</var>] [<var>URL-path</var>]
|
||
<var>URL</var></code></td></tr>
|
||
<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
|
||
<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
|
||
<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
|
||
<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_alias</td></tr>
|
||
</table>
|
||
<p>The <code class="directive">Redirect</code> directive maps an old URL into a new one by asking
|
||
the client to refetch the resource at the new location.</p>
|
||
|
||
<p>The old <em>URL-path</em> is a case-sensitive (%-decoded) path
|
||
beginning with a slash. A relative path is not allowed.</p>
|
||
|
||
<p>The new <em>URL</em> may be either an absolute URL beginning
|
||
with a scheme and hostname, or a URL-path beginning with a slash.
|
||
In this latter case the scheme and hostname of the current server
|
||
will be added if you have
|
||
<code class="directive"><a href="../mod/core.html#usecanonicalname">UseCanonicalName</a></code> set to on,
|
||
otherwise the hostname will be replaced with the requested Host
|
||
header.</p>
|
||
|
||
<p>Then any request beginning with <em>URL-path</em> will return a
|
||
redirect request to the client at the location of the target
|
||
<em>URL</em>. Additional path information beyond the matched
|
||
<em>URL-path</em> will be appended to the target URL.</p>
|
||
|
||
<pre class="prettyprint lang-config"># Redirect to a URL on a different host
|
||
Redirect "/service" "http://foo2.example.com/service"
|
||
|
||
# Redirect to a URL on the same host
|
||
Redirect "/one" "/two"</pre>
|
||
|
||
|
||
<p>If the client requests <code>http://example.com/service/foo.txt</code>,
|
||
it will be told to access
|
||
<code>http://foo2.example.com/service/foo.txt</code>
|
||
instead. This includes requests with <code>GET</code> parameters, such as
|
||
<code>http://example.com/service/foo.pl?q=23&a=42</code>,
|
||
it will be redirected to
|
||
<code>http://foo2.example.com/service/foo.pl?q=23&a=42</code>.
|
||
Note that <code>POST</code>s will be discarded.<br />
|
||
Only complete path segments are matched, so the above
|
||
example would not match a request for
|
||
<code>http://example.com/servicefoo.txt</code>. For more complex matching
|
||
using the <a href="../expr.html">expression syntax</a>, omit the URL-path
|
||
argument as described below. Alternatively, for matching using regular
|
||
expressions, see the <code class="directive"><a href="#redirectmatch">RedirectMatch</a></code> directive.</p>
|
||
|
||
|
||
<div class="note"><h3>Note</h3>
|
||
<p><code class="directive">Redirect</code> directives take precedence over <code class="directive"><a href="#alias">Alias</a></code> and <code class="directive"><a href="#scriptalias">ScriptAlias</a></code>
|
||
directives, irrespective of their ordering in the configuration
|
||
file. <code class="directive">Redirect</code> directives inside a Location take
|
||
precedence over <code class="directive">Redirect</code> and <code class="directive"><a href="#alias">Alias</a></code> directives with an <var>URL-path</var>.</p>
|
||
</div>
|
||
|
||
<p>If no <var>status</var> argument is given, the redirect will
|
||
be "temporary" (HTTP status 302). This indicates to the client
|
||
that the resource has moved temporarily. The <var>status</var>
|
||
argument can be used to return other HTTP status codes:</p>
|
||
|
||
<dl>
|
||
<dt>permanent</dt>
|
||
|
||
<dd>Returns a permanent redirect status (301) indicating that
|
||
the resource has moved permanently.</dd>
|
||
|
||
<dt>temp</dt>
|
||
|
||
<dd>Returns a temporary redirect status (302). This is the
|
||
default.</dd>
|
||
|
||
<dt>seeother</dt>
|
||
|
||
<dd>Returns a "See Other" status (303) indicating that the
|
||
resource has been replaced.</dd>
|
||
|
||
<dt>gone</dt>
|
||
|
||
<dd>Returns a "Gone" status (410) indicating that the
|
||
resource has been permanently removed. When this status is
|
||
used the <var>URL</var> argument should be omitted.</dd>
|
||
</dl>
|
||
|
||
<p>Other status codes can be returned by giving the numeric
|
||
status code as the value of <var>status</var>. If the status is
|
||
between 300 and 399, the <var>URL</var> argument must be present.
|
||
If the status is <em>not</em> between 300 and 399, the
|
||
<var>URL</var> argument must be omitted. The status must be a valid
|
||
HTTP status code, known to the Apache HTTP Server (see the function
|
||
<code>send_error_response</code> in http_protocol.c).</p>
|
||
|
||
<pre class="prettyprint lang-config">Redirect permanent "/one" "http://example.com/two"
|
||
Redirect 303 "/three" "http://example.com/other"</pre>
|
||
|
||
|
||
<p>If the <code class="directive">Redirect</code> directive is used within a
|
||
<code class="directive"><a href="../mod/core.html#location"><Location></a></code>
|
||
or <code class="directive"><a href="../mod/core.html#locationmatch"><LocationMatch></a></code>
|
||
section with the <var>URL-path</var> omitted, then the <var>URL</var> parameter
|
||
will be interpreted using <a href="../expr.html">expression syntax</a>.<br />
|
||
This syntax is available in Apache 2.4.19 and later.</p>
|
||
|
||
<pre class="prettyprint lang-config"><Location "/one">
|
||
Redirect permanent "http://example.com/two"
|
||
</Location>
|
||
<Location "/three">
|
||
Redirect 303 "http://example.com/other"
|
||
</Location>
|
||
<LocationMatch "/error/(?<NUMBER>[0-9]+)">
|
||
Redirect permanent "http://example.com/errors/%{env:MATCH_NUMBER}.html"
|
||
</LocationMatch></pre>
|
||
|
||
|
||
|
||
</div>
|
||
<div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
|
||
<div class="directive-section"><h2><a name="RedirectMatch" id="RedirectMatch">RedirectMatch</a> <a name="redirectmatch" id="redirectmatch">Directive</a> <a title="Permanent link" href="#redirectmatch" class="permalink">¶</a></h2>
|
||
<table class="directive">
|
||
<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sends an external redirect based on a regular expression match
|
||
of the current URL</td></tr>
|
||
<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RedirectMatch [<var>status</var>] <var>regex</var>
|
||
<var>URL</var></code></td></tr>
|
||
<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
|
||
<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
|
||
<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
|
||
<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_alias</td></tr>
|
||
</table>
|
||
<p>This directive is equivalent to <code class="directive"><a href="#redirect">Redirect</a></code>, but makes use of
|
||
<a class="glossarylink" href="../glossary.html#regex" title="see glossary">regular expressions</a>,
|
||
instead of simple prefix matching. The
|
||
supplied regular expression is matched against the URL-path, and
|
||
if it matches, the server will substitute any parenthesized
|
||
matches into the given string and use it as a filename. For
|
||
example, to redirect all GIF files to like-named JPEG files on
|
||
another server, one might use:</p>
|
||
|
||
<pre class="prettyprint lang-config">RedirectMatch "(.*)\.gif$" "http://other.example.com$1.jpg"</pre>
|
||
|
||
|
||
<p>The considerations related to the difference between
|
||
<code class="directive"><a href="#alias">Alias</a></code> and
|
||
<code class="directive"><a href="#aliasmatch">AliasMatch</a></code>
|
||
also apply to the difference between
|
||
<code class="directive"><a href="#redirect">Redirect</a></code> and
|
||
<code class="directive">RedirectMatch</code>.
|
||
See <code class="directive"><a href="#aliasmatch">AliasMatch</a></code> for
|
||
details.</p>
|
||
|
||
|
||
</div>
|
||
<div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
|
||
<div class="directive-section"><h2><a name="RedirectPermanent" id="RedirectPermanent">RedirectPermanent</a> <a name="redirectpermanent" id="redirectpermanent">Directive</a> <a title="Permanent link" href="#redirectpermanent" class="permalink">¶</a></h2>
|
||
<table class="directive">
|
||
<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sends an external permanent redirect asking the client to fetch
|
||
a different URL</td></tr>
|
||
<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RedirectPermanent <var>URL-path</var> <var>URL</var></code></td></tr>
|
||
<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
|
||
<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
|
||
<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
|
||
<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_alias</td></tr>
|
||
</table>
|
||
<p>This directive makes the client know that the Redirect is
|
||
permanent (status 301). Exactly equivalent to <code>Redirect
|
||
permanent</code>.</p>
|
||
|
||
</div>
|
||
<div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
|
||
<div class="directive-section"><h2><a name="RedirectRelative" id="RedirectRelative">RedirectRelative</a> <a name="redirectrelative" id="redirectrelative">Directive</a> <a title="Permanent link" href="#redirectrelative" class="permalink">¶</a></h2>
|
||
<table class="directive">
|
||
<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Allows relative redirect targets.</td></tr>
|
||
<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RedirectRelative On|Off</code></td></tr>
|
||
<tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>RedirectRelative Off</code></td></tr>
|
||
<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory</td></tr>
|
||
<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
|
||
<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_alias</td></tr>
|
||
<tr><th><a href="directive-dict.html#Compatibility">Compatibility:</a></th><td>2.5.1 and later</td></tr>
|
||
</table>
|
||
<p>By default, if the target URL of a <code class="directive"><a href="#redirect">Redirect</a></code>
|
||
directive is a relative URL beginning with a '/' character, the server
|
||
converts it to an absolute URL before responding to the client. By
|
||
setting <code class="directive">RedirectRelative</code> to the value "On",
|
||
the relative URL is presented to the client directly.</p>
|
||
|
||
|
||
</div>
|
||
<div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
|
||
<div class="directive-section"><h2><a name="RedirectTemp" id="RedirectTemp">RedirectTemp</a> <a name="redirecttemp" id="redirecttemp">Directive</a> <a title="Permanent link" href="#redirecttemp" class="permalink">¶</a></h2>
|
||
<table class="directive">
|
||
<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sends an external temporary redirect asking the client to fetch
|
||
a different URL</td></tr>
|
||
<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RedirectTemp <var>URL-path</var> <var>URL</var></code></td></tr>
|
||
<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
|
||
<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
|
||
<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
|
||
<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_alias</td></tr>
|
||
</table>
|
||
<p>This directive makes the client know that the Redirect is
|
||
only temporary (status 302). Exactly equivalent to
|
||
<code>Redirect temp</code>.</p>
|
||
|
||
</div>
|
||
<div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
|
||
<div class="directive-section"><h2><a name="ScriptAlias" id="ScriptAlias">ScriptAlias</a> <a name="scriptalias" id="scriptalias">Directive</a> <a title="Permanent link" href="#scriptalias" class="permalink">¶</a></h2>
|
||
<table class="directive">
|
||
<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Maps a URL to a filesystem location and designates the
|
||
target as a CGI script</td></tr>
|
||
<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>ScriptAlias [<var>URL-path</var>]
|
||
<var>file-path</var>|<var>directory-path</var></code></td></tr>
|
||
<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory</td></tr>
|
||
<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
|
||
<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_alias</td></tr>
|
||
</table>
|
||
<p>The <code class="directive">ScriptAlias</code> directive has the same
|
||
behavior as the <code class="directive"><a href="#alias">Alias</a></code>
|
||
directive, except that in addition it marks the target directory
|
||
as containing CGI scripts that will be processed by <code class="module"><a href="../mod/mod_cgi.html">mod_cgi</a></code>'s cgi-script handler. URLs with a case-sensitive
|
||
(%-decoded) path beginning with <var>URL-path</var> will be mapped
|
||
to scripts beginning with the second argument, which is a full
|
||
pathname in the local filesystem.</p>
|
||
|
||
<pre class="prettyprint lang-config">ScriptAlias "/cgi-bin/" "/web/cgi-bin/"</pre>
|
||
|
||
|
||
<p>A request for <code>http://example.com/cgi-bin/foo</code> would cause the
|
||
server to run the script <code>/web/cgi-bin/foo</code>. This configuration
|
||
is essentially equivalent to:</p>
|
||
<pre class="prettyprint lang-config">Alias "/cgi-bin/" "/web/cgi-bin/"
|
||
<Location "/cgi-bin">
|
||
SetHandler cgi-script
|
||
Options +ExecCGI
|
||
</Location></pre>
|
||
|
||
|
||
<p><code class="directive">ScriptAlias</code> can also be used in conjunction with
|
||
a script or handler you have. For example:</p>
|
||
|
||
<pre class="prettyprint lang-config">ScriptAlias "/cgi-bin/" "/web/cgi-handler.pl"</pre>
|
||
|
||
|
||
<p>In this scenario all files requested in <code>/cgi-bin/</code> will be
|
||
handled by the file you have configured, this allows you to use your own custom
|
||
handler. You may want to use this as a wrapper for CGI so that you can add
|
||
content, or some other bespoke action.</p>
|
||
|
||
<div class="warning">It is safer to avoid placing CGI scripts under the
|
||
<code class="directive"><a href="../mod/core.html#documentroot">DocumentRoot</a></code> in order to
|
||
avoid accidentally revealing their source code if the
|
||
configuration is ever changed. The
|
||
<code class="directive">ScriptAlias</code> makes this easy by mapping a
|
||
URL and designating CGI scripts at the same time. If you do
|
||
choose to place your CGI scripts in a directory already
|
||
accessible from the web, do not use
|
||
<code class="directive">ScriptAlias</code>. Instead, use <code class="directive"><a href="../mod/core.html#directory"><Directory></a></code>, <code class="directive"><a href="../mod/core.html#sethandler">SetHandler</a></code>, and <code class="directive"><a href="../mod/core.html#options">Options</a></code> as in:
|
||
<pre class="prettyprint lang-config"><Directory "/usr/local/apache2/htdocs/cgi-bin">
|
||
SetHandler cgi-script
|
||
Options ExecCGI
|
||
</Directory></pre>
|
||
|
||
This is necessary since multiple <var>URL-paths</var> can map
|
||
to the same filesystem location, potentially bypassing the
|
||
<code class="directive">ScriptAlias</code> and revealing the source code
|
||
of the CGI scripts if they are not restricted by a
|
||
<code class="directive"><a href="../mod/core.html#directory">Directory</a></code> section.</div>
|
||
|
||
<p>If the <code class="directive">ScriptAlias</code> directive is used within
|
||
a <code class="directive"><a href="../mod/core.html#location"><Location></a></code>
|
||
or <code class="directive"><a href="../mod/core.html#locationmatch"><LocationMatch></a></code>
|
||
section with the URL-path omitted, then the URL parameter will be
|
||
interpreted using <a href="../expr.html">expression syntax</a>.<br />
|
||
This syntax is available in Apache 2.4.19 and later.</p>
|
||
|
||
<pre class="prettyprint lang-config"><Location "/cgi-bin">
|
||
ScriptAlias "/web/cgi-bin/"
|
||
</Location>
|
||
<LocationMatch "/cgi-bin/errors/(?<NUMBER>[0-9]+)">
|
||
ScriptAlias "/web/cgi-bin/errors/%{env:MATCH_NUMBER}.cgi"
|
||
</LocationMatch></pre>
|
||
|
||
|
||
|
||
<h3>See also</h3>
|
||
<ul>
|
||
<li><a href="../howto/cgi.html">CGI Tutorial</a></li>
|
||
</ul>
|
||
</div>
|
||
<div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
|
||
<div class="directive-section"><h2><a name="ScriptAliasMatch" id="ScriptAliasMatch">ScriptAliasMatch</a> <a name="scriptaliasmatch" id="scriptaliasmatch">Directive</a> <a title="Permanent link" href="#scriptaliasmatch" class="permalink">¶</a></h2>
|
||
<table class="directive">
|
||
<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Maps a URL to a filesystem location using a regular expression
|
||
and designates the target as a CGI script</td></tr>
|
||
<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>ScriptAliasMatch <var>regex</var>
|
||
<var>file-path</var>|<var>directory-path</var></code></td></tr>
|
||
<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
|
||
<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
|
||
<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_alias</td></tr>
|
||
</table>
|
||
<p>This directive is equivalent to <code class="directive"><a href="#scriptalias">ScriptAlias</a></code>, but makes use of
|
||
<a class="glossarylink" href="../glossary.html#regex" title="see glossary">regular expressions</a>,
|
||
instead of simple prefix matching. The
|
||
supplied regular expression is matched against the URL-path,
|
||
and if it matches, the server will substitute any parenthesized
|
||
matches into the given string and use it as a filename. For
|
||
example, to activate the standard <code>/cgi-bin</code>, one
|
||
might use:</p>
|
||
|
||
<pre class="prettyprint lang-config">ScriptAliasMatch "^/cgi-bin(.*)" "/usr/local/apache/cgi-bin$1"</pre>
|
||
|
||
|
||
<p>As for AliasMatch, the full range of <a class="glossarylink" href="../glossary.html#rexex" title="see glossary">regular
|
||
expression</a> power is available.
|
||
For example, it is possible to construct an alias with case-insensitive
|
||
matching of the URL-path:</p>
|
||
|
||
<pre class="prettyprint lang-config">ScriptAliasMatch "(?i)^/cgi-bin(.*)" "/usr/local/apache/cgi-bin$1"</pre>
|
||
|
||
|
||
<p>The considerations related to the difference between
|
||
<code class="directive"><a href="#alias">Alias</a></code> and
|
||
<code class="directive"><a href="#aliasmatch">AliasMatch</a></code>
|
||
also apply to the difference between
|
||
<code class="directive"><a href="#scriptalias">ScriptAlias</a></code> and
|
||
<code class="directive">ScriptAliasMatch</code>.
|
||
See <code class="directive"><a href="#aliasmatch">AliasMatch</a></code> for
|
||
details.</p>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
<div class="bottomlang">
|
||
<p><span>Available Languages: </span><a href="../en/mod/mod_alias.html" title="English"> en </a> |
|
||
<a href="../es/mod/mod_alias.html" hreflang="es" rel="alternate" title="Español"> es </a> |
|
||
<a href="../fr/mod/mod_alias.html" hreflang="fr" rel="alternate" title="Français"> fr </a> |
|
||
<a href="../ja/mod/mod_alias.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> |
|
||
<a href="../ko/mod/mod_alias.html" hreflang="ko" rel="alternate" title="Korean"> ko </a> |
|
||
<a href="../tr/mod/mod_alias.html" hreflang="tr" rel="alternate" title="Türkçe"> tr </a></p>
|
||
</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 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 Libera.chat, or sent to our <a href="https://httpd.apache.org/lists.html">mailing lists</a>.</div>
|
||
<script type="text/javascript"><!--//--><![CDATA[//><!--
|
||
var comments_shortname = 'httpd';
|
||
var comments_identifier = 'http://httpd.apache.org/docs/trunk/mod/mod_alias.html';
|
||
(function(w, d) {
|
||
if (w.location.hostname.toLowerCase() == "httpd.apache.org") {
|
||
d.write('<div id="comments_thread"><\/div>');
|
||
var s = d.createElement('script');
|
||
s.type = 'text/javascript';
|
||
s.async = true;
|
||
s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
|
||
(d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
|
||
}
|
||
else {
|
||
d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>');
|
||
}
|
||
})(window, document);
|
||
//--><!]]></script></div><div id="footer">
|
||
<p class="apache">Copyright 2023 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/quickreference.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[//><!--
|
||
if (typeof(prettyPrint) !== 'undefined') {
|
||
prettyPrint();
|
||
}
|
||
//--><!]]></script>
|
||
</body></html> |