mod_alias.html revision 29ad0bbaf3e50df92b20e24b42f6e292b5c540e3
bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen<HTML>
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen<HEAD>
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen<TITLE>Apache module mod_alias</TITLE>
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen</HEAD>
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen<!-- Background white, links blue (unvisited), navy (visited), red (active) -->
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen<BODY
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen BGCOLOR="#FFFFFF"
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen TEXT="#000000"
99a9e14caaf54d884dac6a520111cfc8849d8323Timo Sirainen LINK="#0000FF"
b1aa228609f9afde184c7facc0c53e3cf6dbe1e3Timo Sirainen VLINK="#000080"
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen ALINK="#FF0000"
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen>
99a9e14caaf54d884dac6a520111cfc8849d8323Timo Sirainen<!--#include virtual="header.html" -->
99a9e14caaf54d884dac6a520111cfc8849d8323Timo Sirainen
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen<H1 ALIGN="CENTER">Module mod_alias</h1>
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen<P>
da7f1a07f583df8905684a7b78469960afd7c78dPhil CarmodyThis module is contained in the <code>mod_alias.c</code> file, and
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainenis compiled in by default. It provides for mapping different parts of the
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainenhost filesystem in the the document tree, and for URL redirection.
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen</P>
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen<H2>Directives</H2>
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen<UL>
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen<li><A HREF="#alias">Alias</A>
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen<li><A HREF="#aliasmatch">AliasMatch</A>
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen<li><A HREF="#redirect">Redirect</A>
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen<li><A HREF="#redirectmatch">RedirectMatch</A>
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen<li><A HREF="#redirecttemp">RedirectTemp</A>
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen<li><A HREF="#redirectperm">RedirectPermanent</A>
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen<li><A HREF="#scriptalias">ScriptAlias</A>
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen<li><A HREF="#scriptaliasmatch">ScriptAliasMatch</A>
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen</UL>
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen<hr>
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen<h2><A name="alias">Alias directive</A></h2>
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen<P>
8ae72ad7d0c69e972cfa65d1e2ce4e3e9a8b765cTimo Sirainen<!--%plaintext &lt;?INDEX {\tt Alias} directive&gt; -->
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen<strong>Syntax:</strong> Alias <em>url-path directory-filename</em><br>
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen<Strong>Context:</strong> server config, virtual host<br>
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen<strong>Status:</strong> Base<br>
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen<strong>Module:</strong> mod_alias
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen</P>
3d4648e56d079f9778fc72450ccc604ffc05babcTimo Sirainen<P>
3d4648e56d079f9778fc72450ccc604ffc05babcTimo SirainenThe Alias directive allows documents to be stored in the local filesystem
3d4648e56d079f9778fc72450ccc604ffc05babcTimo Sirainenother than under the <A HREF="core.html#documentroot">DocumentRoot</A>.
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo SirainenURLs with a (%-decoded) path beginning with <em>url-path</em> will be
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainenmapped to local files beginning with <em>directory-filename</em>.
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen<P>
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo SirainenExample:
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen</P>
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen<blockquote><code>Alias /image /ftp/pub/image</code></blockquote>
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen<P>
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo SirainenA request for http://myserver/image/foo.gif would cause the server to
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainenreturn the file /ftp/pub/image/foo.gif.
36757b426f4761dbd837bdddc8998e22d09dc869Timo Sirainen</p>
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen<P>
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo SirainenNote that if you include a trailing / on the <em>url-path</em> then the
19e7781f15dbfe52387f40e26b75f938a7f2a7fcTimo Sirainenserver will require a trailing / in order to expand the alias. That is,
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainenif you use <code>Alias /icons/ /usr/local/etc/httpd/icons/</code> then
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainenthe url <code>/icons</code> will not be aliased.
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen</p>
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen<P>
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo SirainenSee also <A HREF="#scriptalias">ScriptAlias</A>.
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen</p>
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen<hr>
36757b426f4761dbd837bdddc8998e22d09dc869Timo Sirainen
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen<h2><A name="aliasmatch">AliasMatch</A></h2>
34d73a1789f9ecf5a159e7152d9d6aef35a7acc3Timo Sirainen<P>
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen<strong>Syntax:</strong> AliasMatch <em>regex directory-filename</em><br>
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen<Strong>Context:</strong> server config, virtual host<br>
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen<strong>Status:</strong> Base<br>
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen<strong>Module:</strong> mod_alias<br>
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen<strong>Compatibility:</strong> Available in Apache 1.3 and later
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen</P>
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen<p>This directive is equivilent to <a href="#alias">Alias</a>, but
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainenmakes use of standard regular expressions, instead of simple prefix
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainenmatching. The supplied regular expression is matched against the URL,
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainenand if it matches, the server will substitute any parenthesized
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainenmatches into the given string and use it as a filename. For example,
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainento activate the <code>/icons</code> directory, one might use:
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen<pre>
447e086422f1ab7cc16833583ed70a4af7a84bc5Timo Sirainen AliasMatch ^/icons(.*) /usr/local/etc/httpd/icons$1
</pre>
</p>
<hr>
<h2><A name="redirect">Redirect directive</A></h2>
<P>
<!--%plaintext &lt;?INDEX {\tt Redirect} directive&gt; -->
<strong>Syntax:</strong> Redirect [ <em>status</em> ] <em>url-path url</em><br>
<Strong>Context:</strong> server config, virtual host, directory, .htaccess<br>
<strong>Status:</strong> Base<br>
<strong>Module:</strong> mod_alias<br>
<strong>Compatibility:</strong> The directory and .htaccess context's
are only available in versions 1.1 and later. The <em>status</em>
argument is only available in Apache 1.2 or later.
</P>
<P>
The Redirect directive maps an old URL into a new one. The new URL is returned
to the client which attempts to fetch it again with the new address.
<em>Url-path</em> a (%-decoded) path; any requests for documents beginning with
this path will be returned a redirect error to a new (%-encoded) url
beginning with <em>url</em>.
</P>
<P>
Example:
</P>
<blockquote><code>Redirect /service
http://foo2.bar.com/service</code></blockquote>
<P>
If the client requests http://myserver/service/foo.txt, it will be told to
access http://foo2.bar.com/service/foo.txt instead.
</p>
<P>
<STRONG>Note:</STRONG> Redirect directives take precedence over Alias
and ScriptAlias
directives, irrespective of their ordering in the configuration file. Also,
<em>Url-path</em> must be an absolute path, not a relative path, even
when used with .htaccess files or inside of &lt;Directory&gt; sections.
</p>
<P>
If no <em>status</em> argument is given, the redirect will be
&quot;temporary&quot; (HTTP status 302). This indicates to the client that the
resources is has moved temporarily. The <em>status</em>
argument can be used to return other HTTP status codes:
<P>
<dl>
<dt>permanent
<dd>Returns a permanent redirect status (301) indicating that
the resource has moved permanently.
<dt>temp
<dd>Returns a temporary redirect status (302). This is the
default.
<dt>seeother
<dd>Returns a "See Other" status (303) indicating that
the resource has been replaced.
<dt>gone
<dd>Returns a "Gone" status (410) indicating that the resource
has been permanently removed. When this status is used the <em>url</em>
argument should be omitted.
</dl>
<P>
Other status codes can be returned by giving the numeric status code
as the value of <em>status</em>. If the status is between 300 and 399,
the <em>url</em> argument must be present, otherwise it must be
omitted. Note that the status must be known to the Apache code (see
the function <code>send_error_response</code> in http_protocol.c).
</P>
<HR>
<h2><A name="redirectmatch">RedirectMatch</A></h2>
<P>
<strong>Syntax:</strong> RedirectMatch [<em>status</em> <em>regex url</em><br>
<Strong>Context:</strong> server config, virtual host<br>
<strong>Status:</strong> Base<br>
<strong>Module:</strong> mod_alias<br>
<strong>Compatibility:</strong> Available in Apache 1.3 and later
</P>
<p>This directive is equivilent to <a href="#alias">Redirect</a>, but
makes use of standard regular expressions, instead of simple prefix
matching. The supplied regular expression is matched against the URL,
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:
<pre>
RedirectMatch (.*)\.gif$ http://www.anotherserver.com$1.jpg
</pre>
</p>
<hr>
<h2><A name="redirecttemp">RedirectTemp directive</A></h2>
<P>
<!--%plaintext &lt;?INDEX {\tt Redirect} directive&gt; -->
<strong>Syntax:</strong> RedirectTemp <em>url-path url</em><br>
<Strong>Context:</strong> server config, virtual host, directory, .htaccess<br>
<strong>Status:</strong> Base<br>
<strong>Module:</strong> mod_alias<br>
<strong>Compatibility:</strong> This directive is only available in 1.2
</P>
<P>
This directive makes the client know that the Redirect is only
temporary (status 302). Exactly equivalent to <code>Redirect
temporary</code>.
</P>
<HR>
<h2><A name="redirectperm">RedirectPermanent directive</A></h2>
<P>
<!--%plaintext &lt;?INDEX {\tt Redirect} directive&gt; -->
<strong>Syntax:</strong> RedirectPermanent <em>url-path url</em><br>
<Strong>Context:</strong> server config, virtual host, directory, .htaccess<br>
<strong>Status:</strong> Base<br>
<strong>Module:</strong> mod_alias<br>
<strong>Compatibility:</strong> This directive is only available in 1.2
</P>
<P>
This directive makes the client know that the Redirect is permanent
(status 301). Exactly equivalent to <code>Redirect permanent</code>.
</P>
<hr>
<h2><A name="scriptalias">ScriptAlias directive</A></h2>
<P>
<!--%plaintext &lt;?INDEX {\tt ScriptAlias} directive&gt; -->
<strong>Syntax:</strong> ScriptAlias <em>url-path directory-filename</em><br>
<Strong>Context:</strong> server config, virtual host<br>
<strong>Status:</strong> Base<br>
<strong>Module:</strong> mod_alias
</P>
<P>
The ScriptAlias directive has the same behavior as the
<A HREF="#alias">Alias</A> directive, except that in addition it
marks the target directory as containing CGI scripts.
URLs with a (%-decoded) path beginning with <em>url-path</em> will be
mapped to scripts beginning with <em>directory-filename</em>.
<P>
Example:
</P>
<blockquote><code>ScriptAlias /cgi-bin/ /web/cgi-bin/</code></blockquote>
<P>
A request for http://myserver/cgi-bin/foo would cause the server to
run the script /web/cgi-bin/foo.
</P>
<hr>
<h2><A name="scriptaliasmatch">ScriptAliasMatch</A></h2>
<P>
<strong>Syntax:</strong> ScriptAliasMatch <em>regex directory-filename</em><br>
<Strong>Context:</strong> server config, virtual host<br>
<strong>Status:</strong> Base<br>
<strong>Module:</strong> mod_alias<br>
<strong>Compatibility:</strong> Available in Apache 1.3 and later
</P>
<p>This directive is equivilent to <a href="#scriptalias">ScriptAlias</a>, but
makes use of standard regular expressions, instead of simple prefix
matching. The supplied regular expression is matched against the URL,
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:
<pre>
ScriptAlias ^/cgi-bin(.*) /usr/local/etc/httpd/cgi-bin$1
</pre>
</p>
<!--#include virtual="footer.html" -->
</BODY>
</HTML>