mod_alias.xml revision f57336f481f784131918fbcab13d5e4d5f4a1be1
22d5d84393d960a2027f472036f3fee15d7dbce9nd<?xml version="1.0"?>
22d5d84393d960a2027f472036f3fee15d7dbce9nd<!DOCTYPE modulesynopsis SYSTEM "/style/modulesynopsis.dtd">
22d5d84393d960a2027f472036f3fee15d7dbce9nd<?xml-stylesheet type="text/xsl" href="/style/manual.en.xsl"?>
22d5d84393d960a2027f472036f3fee15d7dbce9nd<!-- $LastChangedRevision$ -->
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd<!--
db479b48bd4d75423ed4a45e15b75089d1a8ad72fielding Licensed to the Apache Software Foundation (ASF) under one or more
db479b48bd4d75423ed4a45e15b75089d1a8ad72fielding contributor license agreements. See the NOTICE file distributed with
db479b48bd4d75423ed4a45e15b75089d1a8ad72fielding this work for additional information regarding copyright ownership.
db479b48bd4d75423ed4a45e15b75089d1a8ad72fielding The ASF licenses this file to You under the Apache License, Version 2.0
db479b48bd4d75423ed4a45e15b75089d1a8ad72fielding (the "License"); you may not use this file except in compliance with
db479b48bd4d75423ed4a45e15b75089d1a8ad72fielding the License. You may obtain a copy of the License at
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd http://www.apache.org/licenses/LICENSE-2.0
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd Unless required by applicable law or agreed to in writing, software
22d5d84393d960a2027f472036f3fee15d7dbce9nd distributed under the License is distributed on an "AS IS" BASIS,
22d5d84393d960a2027f472036f3fee15d7dbce9nd WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22d5d84393d960a2027f472036f3fee15d7dbce9nd See the License for the specific language governing permissions and
22d5d84393d960a2027f472036f3fee15d7dbce9nd limitations under the License.
22d5d84393d960a2027f472036f3fee15d7dbce9nd-->
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd<modulesynopsis metafile="mod_alias.xml.meta">
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd<name>mod_alias</name>
22d5d84393d960a2027f472036f3fee15d7dbce9nd<description>Provides for mapping different parts of the host
22d5d84393d960a2027f472036f3fee15d7dbce9nd filesystem in the document tree and for URL redirection</description>
22d5d84393d960a2027f472036f3fee15d7dbce9nd<status>Base</status>
22d5d84393d960a2027f472036f3fee15d7dbce9nd<sourcefile>mod_alias.c</sourcefile>
22d5d84393d960a2027f472036f3fee15d7dbce9nd<identifier>alias_module</identifier>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd<summary>
22d5d84393d960a2027f472036f3fee15d7dbce9nd <p>The directives contained in this module allow for manipulation
22d5d84393d960a2027f472036f3fee15d7dbce9nd and control of URLs as requests arrive at the server. The
22d5d84393d960a2027f472036f3fee15d7dbce9nd <directive module="mod_alias">Alias</directive> and <directive
22d5d84393d960a2027f472036f3fee15d7dbce9nd module="mod_alias">ScriptAlias</directive> directives are used to
22d5d84393d960a2027f472036f3fee15d7dbce9nd map between URLs and filesystem paths. This allows for content
22d5d84393d960a2027f472036f3fee15d7dbce9nd which is not directly under the <directive
22d5d84393d960a2027f472036f3fee15d7dbce9nd module="core">DocumentRoot</directive> served as part of the web
22d5d84393d960a2027f472036f3fee15d7dbce9nd document tree. The <directive
22d5d84393d960a2027f472036f3fee15d7dbce9nd module="mod_alias">ScriptAlias</directive> directive has the
22d5d84393d960a2027f472036f3fee15d7dbce9nd additional effect of marking the target directory as containing
22d5d84393d960a2027f472036f3fee15d7dbce9nd only CGI scripts.</p>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd <p>The <directive module="mod_alias">Redirect</directive>
22d5d84393d960a2027f472036f3fee15d7dbce9nd directives are used to instruct clients to make a new request with
22d5d84393d960a2027f472036f3fee15d7dbce9nd a different URL. They are often used when a resource has moved to
22d5d84393d960a2027f472036f3fee15d7dbce9nd a new location.</p>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd <p><module>mod_alias</module> is designed to handle simple URL
22d5d84393d960a2027f472036f3fee15d7dbce9nd manipulation tasks. For more complicated tasks such as
22d5d84393d960a2027f472036f3fee15d7dbce9nd manipulating the query string, use the tools provided by
22d5d84393d960a2027f472036f3fee15d7dbce9nd <module>mod_rewrite</module>.</p>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd</summary>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd<seealso><module>mod_rewrite</module></seealso> <seealso><a
22d5d84393d960a2027f472036f3fee15d7dbce9ndhref="/urlmapping.html">Mapping URLs to the filesystem</a></seealso>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd<section id="order"><title>Order of Processing</title>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd <p>Aliases and Redirects occuring in different contexts are processed
22d5d84393d960a2027f472036f3fee15d7dbce9nd like other directives according to standard <a
22d5d84393d960a2027f472036f3fee15d7dbce9nd href="/sections.html#mergin">merging rules</a>. But when multiple
22d5d84393d960a2027f472036f3fee15d7dbce9nd Aliases or Redirects occur in the same context (for example, in the
22d5d84393d960a2027f472036f3fee15d7dbce9nd same <directive type="section" module="core">VirtualHost</directive>
22d5d84393d960a2027f472036f3fee15d7dbce9nd section) they are processed in a particular order.</p>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd <p>First, all Redirects are processed before Aliases are processed,
22d5d84393d960a2027f472036f3fee15d7dbce9nd and therefore a request that matches a <directive
22d5d84393d960a2027f472036f3fee15d7dbce9nd module="mod_alias">Redirect</directive> or <directive
22d5d84393d960a2027f472036f3fee15d7dbce9nd module="mod_alias">RedirectMatch</directive> will never have Aliases
22d5d84393d960a2027f472036f3fee15d7dbce9nd applied. Second, the Aliases and Redirects are processed in the order
22d5d84393d960a2027f472036f3fee15d7dbce9nd they appear in the configuration files, with the first match taking
22d5d84393d960a2027f472036f3fee15d7dbce9nd precedence.</p>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd <p>For this reason, when two or more of these directives apply to the
22d5d84393d960a2027f472036f3fee15d7dbce9nd same sub-path, you must list the most specific path first in order for
22d5d84393d960a2027f472036f3fee15d7dbce9nd all the directives to have an effect. For example, the following
22d5d84393d960a2027f472036f3fee15d7dbce9nd configuration will work as expected:</p>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd <example>
22d5d84393d960a2027f472036f3fee15d7dbce9nd Alias /foo/bar /baz<br />
22d5d84393d960a2027f472036f3fee15d7dbce9nd Alias /foo /gaq
22d5d84393d960a2027f472036f3fee15d7dbce9nd </example>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd <p>But if the above two directives were reversed in order, the
22d5d84393d960a2027f472036f3fee15d7dbce9nd <code>/foo</code> <directive module="mod_alias">Alias</directive>
22d5d84393d960a2027f472036f3fee15d7dbce9nd would always match before the <code>/foo/bar</code> <directive
22d5d84393d960a2027f472036f3fee15d7dbce9nd module="mod_alias">Alias</directive>, so the latter directive would be
22d5d84393d960a2027f472036f3fee15d7dbce9nd ignored.</p>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper</section>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd<directivesynopsis>
22d5d84393d960a2027f472036f3fee15d7dbce9nd<name>Alias</name>
22d5d84393d960a2027f472036f3fee15d7dbce9nd<description>Maps URLs to filesystem locations</description>
22d5d84393d960a2027f472036f3fee15d7dbce9nd<syntax>Alias <var>URL-path</var>
22d5d84393d960a2027f472036f3fee15d7dbce9nd<var>file-path</var>|<var>directory-path</var></syntax>
22d5d84393d960a2027f472036f3fee15d7dbce9nd<contextlist><context>server config</context><context>virtual host</context>
22d5d84393d960a2027f472036f3fee15d7dbce9nd</contextlist>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd<usage>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd <p>The <directive>Alias</directive> directive allows documents to
22d5d84393d960a2027f472036f3fee15d7dbce9nd be stored in the local filesystem other than under the
22d5d84393d960a2027f472036f3fee15d7dbce9nd <directive module="core">DocumentRoot</directive>. URLs with a
22d5d84393d960a2027f472036f3fee15d7dbce9nd (%-decoded) path beginning with <var>url-path</var> will be mapped
22d5d84393d960a2027f472036f3fee15d7dbce9nd to local files beginning with <var>directory-path</var>. The
22d5d84393d960a2027f472036f3fee15d7dbce9nd <var>url-path</var> is case-sensitive, even on case-insensitive
22d5d84393d960a2027f472036f3fee15d7dbce9nd file systems.</p>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd <example><title>Example:</title>
22d5d84393d960a2027f472036f3fee15d7dbce9nd Alias /image /ftp/pub/image
22d5d84393d960a2027f472036f3fee15d7dbce9nd </example>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd <p>A request for <code>http://myserver/image/foo.gif</code> would cause
22d5d84393d960a2027f472036f3fee15d7dbce9nd the server to return the file <code>/ftp/pub/image/foo.gif</code>. Only
22d5d84393d960a2027f472036f3fee15d7dbce9nd complete path segments are matched, so the above alias would not match a
22d5d84393d960a2027f472036f3fee15d7dbce9nd request for <code>http://myserver/imagefoo.gif</code>. For more complex
22d5d84393d960a2027f472036f3fee15d7dbce9nd matching using regular expressions, see the <directive module="mod_alias"
22d5d84393d960a2027f472036f3fee15d7dbce9nd >AliasMatch</directive> directive.</p>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd <p>Note that if you include a trailing / on the
22d5d84393d960a2027f472036f3fee15d7dbce9nd <var>url-path</var> then the server will require a trailing / in
22d5d84393d960a2027f472036f3fee15d7dbce9nd order to expand the alias. That is, if you use</p>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd <dl><dd><code>Alias /icons/ /usr/local/apache/icons/</code></dd></dl>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd <p>then the url <code>/icons</code> will not be aliased, as it lacks
22d5d84393d960a2027f472036f3fee15d7dbce9nd that trailing /. Likewise, if you omit the slash on the
22d5d84393d960a2027f472036f3fee15d7dbce9nd <var>url-path</var> then you must also omit it from the
22d5d84393d960a2027f472036f3fee15d7dbce9nd <var>file-path</var>.</p>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd <p>Note that you may need to specify additional <directive
22d5d84393d960a2027f472036f3fee15d7dbce9nd type="section" module="core">Directory</directive> sections which
22d5d84393d960a2027f472036f3fee15d7dbce9nd cover the <em>destination</em> of aliases. Aliasing occurs before
22d5d84393d960a2027f472036f3fee15d7dbce9nd <directive type="section" module="core">Directory</directive> sections
22d5d84393d960a2027f472036f3fee15d7dbce9nd are checked, so only the destination of aliases are affected.
22d5d84393d960a2027f472036f3fee15d7dbce9nd (Note however <directive type="section" module="core">Location</directive>
22d5d84393d960a2027f472036f3fee15d7dbce9nd sections are run through once before aliases are performed, so
22d5d84393d960a2027f472036f3fee15d7dbce9nd they will apply.)</p>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd <p>In particular, if you are creating an <code>Alias</code> to a
22d5d84393d960a2027f472036f3fee15d7dbce9nd directory outside of your <directive
22d5d84393d960a2027f472036f3fee15d7dbce9nd module="core">DocumentRoot</directive>, you may need to explicitly
22d5d84393d960a2027f472036f3fee15d7dbce9nd permit access to the target directory.</p>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd <example><title>Example:</title>
22d5d84393d960a2027f472036f3fee15d7dbce9nd Alias /image /ftp/pub/image<br />
22d5d84393d960a2027f472036f3fee15d7dbce9nd &lt;Directory /ftp/pub/image&gt;<br />
22d5d84393d960a2027f472036f3fee15d7dbce9nd <indent>
22d5d84393d960a2027f472036f3fee15d7dbce9nd Require all granted<br />
22d5d84393d960a2027f472036f3fee15d7dbce9nd </indent>
22d5d84393d960a2027f472036f3fee15d7dbce9nd &lt;/Directory&gt;
22d5d84393d960a2027f472036f3fee15d7dbce9nd </example>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd</usage>
22d5d84393d960a2027f472036f3fee15d7dbce9nd</directivesynopsis>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd<directivesynopsis>
22d5d84393d960a2027f472036f3fee15d7dbce9nd<name>AliasMatch</name>
22d5d84393d960a2027f472036f3fee15d7dbce9nd<description>Maps URLs to filesystem locations using regular
22d5d84393d960a2027f472036f3fee15d7dbce9ndexpressions</description>
22d5d84393d960a2027f472036f3fee15d7dbce9nd<syntax>AliasMatch <var>regex</var>
22d5d84393d960a2027f472036f3fee15d7dbce9nd<var>file-path</var>|<var>directory-path</var></syntax>
22d5d84393d960a2027f472036f3fee15d7dbce9nd<contextlist><context>server config</context><context>virtual host</context>
22d5d84393d960a2027f472036f3fee15d7dbce9nd</contextlist>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd<usage>
22d5d84393d960a2027f472036f3fee15d7dbce9nd <p>This directive is equivalent to <directive
22d5d84393d960a2027f472036f3fee15d7dbce9nd module="mod_alias">Alias</directive>, but makes use of
22d5d84393d960a2027f472036f3fee15d7dbce9nd <glossary ref="regex">regular expressions</glossary>,
22d5d84393d960a2027f472036f3fee15d7dbce9nd instead of simple prefix matching. The
22d5d84393d960a2027f472036f3fee15d7dbce9nd supplied regular expression is matched against the URL-path, and
22d5d84393d960a2027f472036f3fee15d7dbce9nd if it matches, the server will substitute any parenthesized
22d5d84393d960a2027f472036f3fee15d7dbce9nd matches into the given string and use it as a filename. For
22d5d84393d960a2027f472036f3fee15d7dbce9nd example, to activate the <code>/icons</code> directory, one might
22d5d84393d960a2027f472036f3fee15d7dbce9nd use:</p>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd <example>
22d5d84393d960a2027f472036f3fee15d7dbce9nd AliasMatch ^/icons(.*) /usr/local/apache/icons$1
22d5d84393d960a2027f472036f3fee15d7dbce9nd </example>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd <p>The full range of <glossary ref="regex">regular expression</glossary>
22d5d84393d960a2027f472036f3fee15d7dbce9nd power is available. For example,
22d5d84393d960a2027f472036f3fee15d7dbce9nd it is possible to construct an alias with case-insensitive
22d5d84393d960a2027f472036f3fee15d7dbce9nd matching of the url-path:</p>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd <example>
22d5d84393d960a2027f472036f3fee15d7dbce9nd AliasMatch (?i)^/image(.*) /ftp/pub/image$1
22d5d84393d960a2027f472036f3fee15d7dbce9nd </example>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd <p>One subtle difference
22d5d84393d960a2027f472036f3fee15d7dbce9nd between <directive module="mod_alias">Alias</directive>
22d5d84393d960a2027f472036f3fee15d7dbce9nd and <directive module="mod_alias">AliasMatch</directive> is
22d5d84393d960a2027f472036f3fee15d7dbce9nd that <directive module="mod_alias">Alias</directive> will
22d5d84393d960a2027f472036f3fee15d7dbce9nd automatically copy any additional part of the URI, past the part
22d5d84393d960a2027f472036f3fee15d7dbce9nd that matched, onto the end of the file path on the right side,
22d5d84393d960a2027f472036f3fee15d7dbce9nd while <directive module="mod_alias">AliasMatch</directive> will
22d5d84393d960a2027f472036f3fee15d7dbce9nd not. This means that in almost all cases, you will want the
22d5d84393d960a2027f472036f3fee15d7dbce9nd regular expression to match the entire request URI from beginning
22d5d84393d960a2027f472036f3fee15d7dbce9nd to end, and to use substitution on the right side.</p>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd <p>In other words, just changing
22d5d84393d960a2027f472036f3fee15d7dbce9nd <directive module="mod_alias">Alias</directive> to
22d5d84393d960a2027f472036f3fee15d7dbce9nd <directive module="mod_alias">AliasMatch</directive> will not
22d5d84393d960a2027f472036f3fee15d7dbce9nd have the same effect. At a minimum, you need to
22d5d84393d960a2027f472036f3fee15d7dbce9nd add <code>^</code> to the beginning of the regular expression
22d5d84393d960a2027f472036f3fee15d7dbce9nd and add <code>(.*)$</code> to the end, and add <code>$1</code> to
22d5d84393d960a2027f472036f3fee15d7dbce9nd the end of the replacement.</p>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd <p>For example, suppose you want to replace this with AliasMatch:</p>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd <example>
22d5d84393d960a2027f472036f3fee15d7dbce9nd Alias /image/ /ftp/pub/image/
22d5d84393d960a2027f472036f3fee15d7dbce9nd </example>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd <p>This is NOT equivalent - don't do this! This will send all
22d5d84393d960a2027f472036f3fee15d7dbce9nd requests that have /image/ anywhere in them to /ftp/pub/image/:</p>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd <example>
22d5d84393d960a2027f472036f3fee15d7dbce9nd AliasMatch /image/ /ftp/pub/image/
22d5d84393d960a2027f472036f3fee15d7dbce9nd </example>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd <p>This is what you need to get the same effect:</p>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd <example>
22d5d84393d960a2027f472036f3fee15d7dbce9nd AliasMatch ^/image/(.*)$ /ftp/pub/image/$1
22d5d84393d960a2027f472036f3fee15d7dbce9nd </example>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd <p>Of course, there's no point in
22d5d84393d960a2027f472036f3fee15d7dbce9nd using <directive module="mod_alias">AliasMatch</directive>
22d5d84393d960a2027f472036f3fee15d7dbce9nd where <directive module="mod_alias">Alias</directive> would
22d5d84393d960a2027f472036f3fee15d7dbce9nd work. <directive module="mod_alias">AliasMatch</directive> lets
22d5d84393d960a2027f472036f3fee15d7dbce9nd you do more complicated things. For example, you could
22d5d84393d960a2027f472036f3fee15d7dbce9nd serve different kinds of files from different directories:</p>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper <example>
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper AliasMatch ^/image/(.*)\.jpg$ /files/jpg.images/$1.jpg<br/>
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper AliasMatch ^/image/(.*)\.gif$ /files/gif.images/$1.gif
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper </example>
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper</usage>
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper</directivesynopsis>
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper<directivesynopsis>
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper<name>Redirect</name>
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper<description>Sends an external redirect asking the client to fetch
b57e88079429c92f4de900e6ac0b27fc3d234b97peppera different URL</description>
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper<syntax>Redirect [<var>status</var>] <var>URL-path</var>
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper<var>URL</var></syntax>
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper<contextlist><context>server config</context><context>virtual host</context>
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper<context>directory</context><context>.htaccess</context></contextlist>
22d5d84393d960a2027f472036f3fee15d7dbce9nd<override>FileInfo</override>
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper<usage>
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper <p>The Redirect directive maps an old URL into a new one by asking
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper the client to refetch the resource at the new location.</p>
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper <p>The old <em>URL-path</em> is a case-sensitive (%-decoded) path
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper beginning with a slash. A relative path is not allowed.</p>
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper <p>The new <em>URL</em> may be either an absolute URL beginning
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper with a scheme and hostname, or a URL-path beginning with a slash.
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper In this latter case the scheme and hostname of the current server will
22d5d84393d960a2027f472036f3fee15d7dbce9nd be added.</p>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd <p>Then any request beginning with <em>URL-Path</em> will return a
22d5d84393d960a2027f472036f3fee15d7dbce9nd redirect request to the client at the location of the target
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper <em>URL</em>. Additional path information beyond the matched
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper <em>URL-Path</em> will be appended to the target URL.</p>
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper <example><title>Example:</title>
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper # Redirect to a URL on a different host<br />
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper Redirect /service http://foo2.example.com/service<br />
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper <br />
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper # Redirect to a URL on the same host<br />
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper Redirect /one /two
22d5d84393d960a2027f472036f3fee15d7dbce9nd </example>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd <p>If the client requests <code>http://example.com/service/foo.txt</code>,
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper it will be told to access
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper <code>http://foo2.example.com/service/foo.txt</code>
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper instead. This includes requests with <code>GET</code> parameters, such as
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper <code>http://example.com/service/foo.pl?q=23&amp;a=42</code>,
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper it will be redirected to
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper <code>http://foo2.example.com/service/foo.pl?q=23&amp;a=42</code>.
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper Note that <code>POST</code>s will be discarded.<br />
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper Only complete path segments are matched, so the above
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper example would not match a request for
22d5d84393d960a2027f472036f3fee15d7dbce9nd <code>http://example.com/servicefoo.txt</code>. For more complex matching
22d5d84393d960a2027f472036f3fee15d7dbce9nd using regular expressions, see the <directive
22d5d84393d960a2027f472036f3fee15d7dbce9nd module="mod_alias">RedirectMatch</directive> directive.</p>
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper
22d5d84393d960a2027f472036f3fee15d7dbce9nd <note><title>Note</title>
22d5d84393d960a2027f472036f3fee15d7dbce9nd <p>Redirect directives take precedence over Alias and ScriptAlias
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper directives, irrespective of their ordering in the configuration
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper file.</p></note>
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper <p>If no <var>status</var> argument is given, the redirect will
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper be "temporary" (HTTP status 302). This indicates to the client
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper that the resource has moved temporarily. The <var>status</var>
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper argument can be used to return other HTTP status codes:</p>
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper <dl>
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper <dt>permanent</dt>
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper <dd>Returns a permanent redirect status (301) indicating that
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper the resource has moved permanently.</dd>
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper <dt>temp</dt>
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper <dd>Returns a temporary redirect status (302). This is the
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper default.</dd>
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper <dt>seeother</dt>
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper <dd>Returns a "See Other" status (303) indicating that the
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper resource has been replaced.</dd>
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper <dt>gone</dt>
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper
22d5d84393d960a2027f472036f3fee15d7dbce9nd <dd>Returns a "Gone" status (410) indicating that the
22d5d84393d960a2027f472036f3fee15d7dbce9nd resource has been permanently removed. When this status is
22d5d84393d960a2027f472036f3fee15d7dbce9nd used the <var>URL</var> argument should be omitted.</dd>
22d5d84393d960a2027f472036f3fee15d7dbce9nd </dl>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd <p>Other status codes can be returned by giving the numeric
22d5d84393d960a2027f472036f3fee15d7dbce9nd status code as the value of <var>status</var>. If the status is
22d5d84393d960a2027f472036f3fee15d7dbce9nd between 300 and 399, the <var>URL</var> argument must be present.
22d5d84393d960a2027f472036f3fee15d7dbce9nd If the status is <em>not</em> between 300 and 399, the
22d5d84393d960a2027f472036f3fee15d7dbce9nd <var>URL</var> argument must be omitted. The status must be a valid
22d5d84393d960a2027f472036f3fee15d7dbce9nd HTTP status code, known to the Apache HTTP Server (see the function
22d5d84393d960a2027f472036f3fee15d7dbce9nd <code>send_error_response</code> in http_protocol.c).</p>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd <example><title>Example:</title>
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper Redirect permanent /one http://example.com/two<br />
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper Redirect 303 /three http://example.com/other
22d5d84393d960a2027f472036f3fee15d7dbce9nd </example>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd</usage>
22d5d84393d960a2027f472036f3fee15d7dbce9nd</directivesynopsis>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd<directivesynopsis>
22d5d84393d960a2027f472036f3fee15d7dbce9nd<name>RedirectMatch</name>
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper<description>Sends an external redirect based on a regular expression match
b57e88079429c92f4de900e6ac0b27fc3d234b97pepperof the current URL</description>
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper<syntax>RedirectMatch [<var>status</var>] <var>regex</var>
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper<var>URL</var></syntax>
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper<contextlist><context>server config</context><context>virtual host</context>
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper<context>directory</context><context>.htaccess</context></contextlist>
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper<override>FileInfo</override>
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper<usage>
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper <p>This directive is equivalent to <directive
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper module="mod_alias">Redirect</directive>, but makes use of
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper <glossary ref="regex">regular expressions</glossary>,
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper instead of simple prefix matching. The
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper supplied regular expression is matched against the URL-path, and
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper if it matches, the server will substitute any parenthesized
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper matches into the given string and use it as a filename. For
22d5d84393d960a2027f472036f3fee15d7dbce9nd example, to redirect all GIF files to like-named JPEG files on
22d5d84393d960a2027f472036f3fee15d7dbce9nd another server, one might use:</p>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd <example>
22d5d84393d960a2027f472036f3fee15d7dbce9nd RedirectMatch (.*)\.gif$ http://other.example.com$1.jpg
22d5d84393d960a2027f472036f3fee15d7dbce9nd </example>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd <p>The considerations related to the difference between
22d5d84393d960a2027f472036f3fee15d7dbce9nd <directive module="mod_alias">Alias</directive> and
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper <directive module="mod_alias">AliasMatch</directive>
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper also apply to the difference between
b57e88079429c92f4de900e6ac0b27fc3d234b97pepper <directive module="mod_alias">Redirect</directive> and
22d5d84393d960a2027f472036f3fee15d7dbce9nd <directive module="mod_alias">RedirectMatch</directive>.
22d5d84393d960a2027f472036f3fee15d7dbce9nd See <directive module="mod_alias">AliasMatch</directive> for
22d5d84393d960a2027f472036f3fee15d7dbce9nd details.</p>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd</usage>
22d5d84393d960a2027f472036f3fee15d7dbce9nd</directivesynopsis>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd<directivesynopsis>
22d5d84393d960a2027f472036f3fee15d7dbce9nd<name>RedirectTemp</name>
22d5d84393d960a2027f472036f3fee15d7dbce9nd<description>Sends an external temporary redirect asking the client to fetch
22d5d84393d960a2027f472036f3fee15d7dbce9nda different URL</description>
22d5d84393d960a2027f472036f3fee15d7dbce9nd<syntax>RedirectTemp <var>URL-path</var> <var>URL</var></syntax>
22d5d84393d960a2027f472036f3fee15d7dbce9nd<contextlist><context>server config</context><context>virtual host</context>
22d5d84393d960a2027f472036f3fee15d7dbce9nd<context>directory</context><context>.htaccess</context></contextlist>
22d5d84393d960a2027f472036f3fee15d7dbce9nd<override>FileInfo</override>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd<usage>
22d5d84393d960a2027f472036f3fee15d7dbce9nd <p>This directive makes the client know that the Redirect is
22d5d84393d960a2027f472036f3fee15d7dbce9nd only temporary (status 302). Exactly equivalent to
22d5d84393d960a2027f472036f3fee15d7dbce9nd <code>Redirect temp</code>.</p>
22d5d84393d960a2027f472036f3fee15d7dbce9nd</usage>
22d5d84393d960a2027f472036f3fee15d7dbce9nd</directivesynopsis>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd<directivesynopsis>
22d5d84393d960a2027f472036f3fee15d7dbce9nd<name>RedirectPermanent</name>
22d5d84393d960a2027f472036f3fee15d7dbce9nd<description>Sends an external permanent redirect asking the client to fetch
22d5d84393d960a2027f472036f3fee15d7dbce9nda different URL</description>
22d5d84393d960a2027f472036f3fee15d7dbce9nd<syntax>RedirectPermanent <var>URL-path</var> <var>URL</var></syntax>
22d5d84393d960a2027f472036f3fee15d7dbce9nd<contextlist><context>server config</context><context>virtual host</context>
22d5d84393d960a2027f472036f3fee15d7dbce9nd<context>directory</context><context>.htaccess</context></contextlist>
22d5d84393d960a2027f472036f3fee15d7dbce9nd<override>FileInfo</override>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd<usage>
22d5d84393d960a2027f472036f3fee15d7dbce9nd <p>This directive makes the client know that the Redirect is
22d5d84393d960a2027f472036f3fee15d7dbce9nd permanent (status 301). Exactly equivalent to <code>Redirect
22d5d84393d960a2027f472036f3fee15d7dbce9nd permanent</code>.</p>
22d5d84393d960a2027f472036f3fee15d7dbce9nd</usage>
22d5d84393d960a2027f472036f3fee15d7dbce9nd</directivesynopsis>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd<directivesynopsis>
22d5d84393d960a2027f472036f3fee15d7dbce9nd<name>ScriptAlias</name>
22d5d84393d960a2027f472036f3fee15d7dbce9nd<description>Maps a URL to a filesystem location and designates the
22d5d84393d960a2027f472036f3fee15d7dbce9ndtarget as a CGI script</description>
22d5d84393d960a2027f472036f3fee15d7dbce9nd<syntax>ScriptAlias <var>URL-path</var>
22d5d84393d960a2027f472036f3fee15d7dbce9nd<var>file-path</var>|<var>directory-path</var></syntax>
22d5d84393d960a2027f472036f3fee15d7dbce9nd<contextlist><context>server config</context><context>virtual host</context>
22d5d84393d960a2027f472036f3fee15d7dbce9nd</contextlist>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd<usage>
22d5d84393d960a2027f472036f3fee15d7dbce9nd <p>The <directive>ScriptAlias</directive> directive has the same
22d5d84393d960a2027f472036f3fee15d7dbce9nd behavior as the <directive module="mod_alias">Alias</directive>
22d5d84393d960a2027f472036f3fee15d7dbce9nd directive, except that in addition it marks the target directory
22d5d84393d960a2027f472036f3fee15d7dbce9nd as containing CGI scripts that will be processed by <module
22d5d84393d960a2027f472036f3fee15d7dbce9nd >mod_cgi</module>'s cgi-script handler. URLs with a case-sensitive
22d5d84393d960a2027f472036f3fee15d7dbce9nd (%-decoded) path beginning with <var>URL-path</var> will be mapped
22d5d84393d960a2027f472036f3fee15d7dbce9nd to scripts beginning with the second argument, which is a full
22d5d84393d960a2027f472036f3fee15d7dbce9nd pathname in the local filesystem.</p>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd <example><title>Example:</title>
22d5d84393d960a2027f472036f3fee15d7dbce9nd ScriptAlias /cgi-bin/ /web/cgi-bin/
22d5d84393d960a2027f472036f3fee15d7dbce9nd </example>
22d5d84393d960a2027f472036f3fee15d7dbce9nd
22d5d84393d960a2027f472036f3fee15d7dbce9nd <p>A request for <code>http://myserver/cgi-bin/foo</code> would cause the
22d5d84393d960a2027f472036f3fee15d7dbce9nd server to run the script <code>/web/cgi-bin/foo</code>. This configuration
22d5d84393d960a2027f472036f3fee15d7dbce9nd is essentially equivalent to:</p>
22d5d84393d960a2027f472036f3fee15d7dbce9nd <example>
22d5d84393d960a2027f472036f3fee15d7dbce9nd Alias /cgi-bin/ /web/cgi-bin/<br />
22d5d84393d960a2027f472036f3fee15d7dbce9nd &lt;Location /cgi-bin &gt;<br />
<indent>
SetHandler cgi-script<br />
Options +ExecCGI<br />
</indent>
&lt;/Location&gt;
</example>
<p><directive>ScriptAlias</directive> can also be used in conjunction with
a script or handler you have. For example:</p>
<example>
ScriptAlias /cgi-bin/ /web/cgi-handler.pl
</example>
<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>
<note type="warning">It is safer to avoid placing CGI scripts under the
<directive module="core">DocumentRoot</directive> in order to
avoid accidentally revealing their source code if the
configuration is ever changed. The
<directive>ScriptAlias</directive> 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
<directive>ScriptAlias</directive>. Instead, use <directive
module="core" type="section">Directory</directive>, <directive
module="core">SetHandler</directive>, and <directive
module="core">Options</directive> as in:
<example>
&lt;Directory /usr/local/apache2/htdocs/cgi-bin &gt;<br />
<indent>
SetHandler cgi-script<br />
Options ExecCGI<br />
</indent>
&lt;/Directory&gt;
</example>
This is necessary since multiple <var>URL-paths</var> can map
to the same filesystem location, potentially bypassing the
<directive>ScriptAlias</directive> and revealing the source code
of the CGI scripts if they are not restricted by a
<directive module="core">Directory</directive> section.</note>
</usage>
<seealso><a href="/howto/cgi.html">CGI Tutorial</a></seealso>
</directivesynopsis>
<directivesynopsis>
<name>ScriptAliasMatch</name>
<description>Maps a URL to a filesystem location using a regular expression
and designates the target as a CGI script</description>
<syntax>ScriptAliasMatch <var>regex</var>
<var>file-path</var>|<var>directory-path</var></syntax>
<contextlist><context>server config</context><context>virtual host</context>
</contextlist>
<usage>
<p>This directive is equivalent to <directive module="mod_alias"
>ScriptAlias</directive>, but makes use of
<glossary ref="regex">regular expressions</glossary>,
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>
<example>
ScriptAliasMatch ^/cgi-bin(.*) /usr/local/apache/cgi-bin$1
</example>
<p>As for AliasMatch, the full range of <glossary ref="rexex">regular
expression</glossary> power is available.
For example, it is possible to construct an alias with case-insensitive
matching of the url-path:</p>
<example>
ScriptAliasMatch (?i)^/cgi-bin(.*) /usr/local/apache/cgi-bin$1
</example>
<p>The considerations related to the difference between
<directive module="mod_alias">Alias</directive> and
<directive module="mod_alias">AliasMatch</directive>
also apply to the difference between
<directive module="mod_alias">ScriptAlias</directive> and
<directive module="mod_alias">ScriptAliasMatch</directive>.
See <directive module="mod_alias">AliasMatch</directive> for
details.</p>
</usage>
</directivesynopsis>
</modulesynopsis>