]> granicus.if.org Git - apache/blob - docs/manual/mod/mod_alias.html.en
Quote {Alias,Redirect,ScriptAlias}{,Match} arguments.
[apache] / docs / manual / mod / mod_alias.html.en
1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
4         XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
5               This file is generated from xml source: DO NOT EDIT
6         XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
7       -->
8 <title>mod_alias - Apache HTTP Server Version 2.5</title>
9 <link href="../style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
10 <link href="../style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
11 <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" />
12 <script src="../style/scripts/prettify.min.js" type="text/javascript">
13 </script>
14
15 <link href="../images/favicon.ico" rel="shortcut icon" /></head>
16 <body>
17 <div id="page-header">
18 <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>
19 <p class="apache">Apache HTTP Server Version 2.5</p>
20 <img alt="" src="../images/feather.gif" /></div>
21 <div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="../images/left.gif" /></a></div>
22 <div id="path">
23 <a href="http://www.apache.org/">Apache</a> &gt; <a href="http://httpd.apache.org/">HTTP Server</a> &gt; <a href="http://httpd.apache.org/docs/">Documentation</a> &gt; <a href="../">Version 2.5</a> &gt; <a href="./">Modules</a></div>
24 <div id="page-content">
25 <div id="preamble"><h1>Apache Module mod_alias</h1>
26 <div class="toplang">
27 <p><span>Available Languages: </span><a href="../en/mod/mod_alias.html" title="English">&nbsp;en&nbsp;</a> |
28 <a href="../fr/mod/mod_alias.html" hreflang="fr" rel="alternate" title="Français">&nbsp;fr&nbsp;</a> |
29 <a href="../ja/mod/mod_alias.html" hreflang="ja" rel="alternate" title="Japanese">&nbsp;ja&nbsp;</a> |
30 <a href="../ko/mod/mod_alias.html" hreflang="ko" rel="alternate" title="Korean">&nbsp;ko&nbsp;</a> |
31 <a href="../tr/mod/mod_alias.html" hreflang="tr" rel="alternate" title="Türkçe">&nbsp;tr&nbsp;</a></p>
32 </div>
33 <table class="module"><tr><th><a href="module-dict.html#Description">Description:</a></th><td>Provides for mapping different parts of the host
34     filesystem in the document tree and for URL redirection</td></tr>
35 <tr><th><a href="module-dict.html#Status">Status:</a></th><td>Base</td></tr>
36 <tr><th><a href="module-dict.html#ModuleIdentifier">Module Identifier:</a></th><td>alias_module</td></tr>
37 <tr><th><a href="module-dict.html#SourceFile">Source File:</a></th><td>mod_alias.c</td></tr></table>
38 <h3>Summary</h3>
39
40     <p>The directives contained in this module allow for manipulation
41     and control of URLs as requests arrive at the server. The
42     <code class="directive"><a href="#alias">Alias</a></code> and <code class="directive"><a href="#scriptalias">ScriptAlias</a></code> directives are used to
43     map between URLs and filesystem paths.  This allows for content
44     which is not directly under the <code class="directive"><a href="../mod/core.html#documentroot">DocumentRoot</a></code> served as part of the web
45     document tree. The <code class="directive"><a href="#scriptalias">ScriptAlias</a></code> directive has the
46     additional effect of marking the target directory as containing
47     only CGI scripts.</p>
48
49     <p>The <code class="directive"><a href="#redirect">Redirect</a></code>
50     directives are used to instruct clients to make a new request with
51     a different URL. They are often used when a resource has moved to
52     a new location.</p>
53
54     <p>When the <code class="directive"><a href="#alias">Alias</a></code>,
55     <code class="directive"><a href="#scriptalias">ScriptAlias</a></code> and 
56     <code class="directive"><a href="#redirect">Redirect</a></code> directives are used
57     within a <code class="directive"><a href="../mod/core.html#location">&lt;Location&gt;</a></code>
58     or <code class="directive"><a href="../mod/core.html#locationmatch">&lt;LocationMatch&gt;</a></code>
59     section, <a href="../expr.html">expression syntax</a> can be used
60     to manipulate the destination path or URL.
61         </p>
62
63     <p><code class="module"><a href="../mod/mod_alias.html">mod_alias</a></code> is designed to handle simple URL
64     manipulation tasks.  For more complicated tasks such as
65     manipulating the query string, use the tools provided by
66     <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code>.</p>
67
68 </div>
69 <div id="quickview"><h3>Topics</h3>
70 <ul id="topics">
71 <li><img alt="" src="../images/down.gif" /> <a href="#order">Order of Processing</a></li>
72 </ul><h3 class="directives">Directives</h3>
73 <ul id="toc">
74 <li><img alt="" src="../images/down.gif" /> <a href="#alias">Alias</a></li>
75 <li><img alt="" src="../images/down.gif" /> <a href="#aliasmatch">AliasMatch</a></li>
76 <li><img alt="" src="../images/down.gif" /> <a href="#redirect">Redirect</a></li>
77 <li><img alt="" src="../images/down.gif" /> <a href="#redirectmatch">RedirectMatch</a></li>
78 <li><img alt="" src="../images/down.gif" /> <a href="#redirectpermanent">RedirectPermanent</a></li>
79 <li><img alt="" src="../images/down.gif" /> <a href="#redirecttemp">RedirectTemp</a></li>
80 <li><img alt="" src="../images/down.gif" /> <a href="#scriptalias">ScriptAlias</a></li>
81 <li><img alt="" src="../images/down.gif" /> <a href="#scriptaliasmatch">ScriptAliasMatch</a></li>
82 </ul>
83 <h3>See also</h3>
84 <ul class="seealso">
85 <li><code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code></li>
86 <li><a href="../urlmapping.html">Mapping URLs to the filesystem</a></li>
87 </ul><ul class="seealso"><li><a href="#comments_section">Comments</a></li></ul></div>
88 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
89 <div class="section">
90 <h2><a name="order" id="order">Order of Processing</a></h2>
91
92     <p>Aliases and Redirects occurring in different contexts are processed
93     like other directives according to standard <a href="../sections.html#mergin">merging rules</a>.  But when multiple
94     Aliases or Redirects occur in the same context (for example, in the
95     same <code class="directive"><a href="../mod/core.html#virtualhost">&lt;VirtualHost&gt;</a></code>
96     section) they are processed in a particular order.</p>
97
98     <p>First, all Redirects are processed before Aliases are processed,
99     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
100     applied.  Second, the Aliases and Redirects are processed in the order
101     they appear in the configuration files, with the first match taking
102     precedence.</p>
103
104     <p>For this reason, when two or more of these directives apply to the
105     same sub-path, you must list the most specific path first in order for
106     all the directives to have an effect.  For example, the following
107     configuration will work as expected:</p>
108
109     <pre class="prettyprint lang-config">Alias "/foo/bar" "/baz"
110 Alias "/foo"     "/gaq"</pre>
111
112
113     <p>But if the above two directives were reversed in order, the
114     <code>/foo</code> <code class="directive"><a href="#alias">Alias</a></code>
115     would always match before the <code>/foo/bar</code> <code class="directive"><a href="#alias">Alias</a></code>, so the latter directive would be
116     ignored.</p>
117
118     <p>When the <code class="directive"><a href="#alias">Alias</a></code>,
119     <code class="directive"><a href="#scriptalias">ScriptAlias</a></code> and 
120     <code class="directive"><a href="#redirect">Redirect</a></code> directives are used
121     within a <code class="directive"><a href="../mod/core.html#location">&lt;Location&gt;</a></code>
122     or <code class="directive"><a href="../mod/core.html#locationmatch">&lt;LocationMatch&gt;</a></code>
123     section, these directives will take precedence over any globally
124     defined <code class="directive"><a href="#alias">Alias</a></code>,
125     <code class="directive"><a href="#scriptalias">ScriptAlias</a></code> and 
126     <code class="directive"><a href="#redirect">Redirect</a></code> directives.</p>
127
128 </div>
129 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
130 <div class="directive-section"><h2><a name="Alias" id="Alias">Alias</a> <a name="alias" id="alias">Directive</a></h2>
131 <table class="directive">
132 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Maps URLs to filesystem locations</td></tr>
133 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>Alias [<var>URL-path</var>]
134 <var>file-path</var>|<var>directory-path</var></code></td></tr>
135 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory</td></tr>
136 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
137 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_alias</td></tr>
138 </table>
139
140     <p>The <code class="directive">Alias</code> directive allows documents to
141     be stored in the local filesystem other than under the
142     <code class="directive"><a href="../mod/core.html#documentroot">DocumentRoot</a></code>. URLs with a
143     (%-decoded) path beginning with <var>URL-path</var> will be mapped
144     to local files beginning with <var>directory-path</var>.  The
145     <var>URL-path</var> is case-sensitive, even on case-insensitive
146     file systems.</p>
147
148     <pre class="prettyprint lang-config">Alias "/image" "/ftp/pub/image"</pre>
149
150
151     <p>A request for <code>http://example.com/image/foo.gif</code> would cause
152     the server to return the file <code>/ftp/pub/image/foo.gif</code>.  Only
153     complete path segments are matched, so the above alias would not match a
154     request for <code>http://example.com/imagefoo.gif</code>.  For more complex
155     matching using regular expressions, see the <code class="directive"><a href="#aliasmatch">AliasMatch</a></code> directive.</p>
156
157     <p>Note that if you include a trailing / on the
158     <var>URL-path</var> then the server will require a trailing / in
159     order to expand the alias. That is, if you use</p>
160
161     <pre class="prettyprint lang-config">Alias "/icons/" "/usr/local/apache/icons/"</pre>
162
163
164     <p>then the url <code>/icons</code> will not be aliased, as it lacks
165     that trailing /. Likewise, if you omit the slash on the
166     <var>URL-path</var> then you must also omit it from the
167     <var>file-path</var>.</p>
168
169     <p>Note that you may need to specify additional <code class="directive"><a href="../mod/core.html#directory">&lt;Directory&gt;</a></code> sections which
170     cover the <em>destination</em> of aliases.  Aliasing occurs before
171     <code class="directive"><a href="../mod/core.html#directory">&lt;Directory&gt;</a></code> sections
172     are checked, so only the destination of aliases are affected.
173     (Note however <code class="directive"><a href="../mod/core.html#location">&lt;Location&gt;</a></code>
174     sections are run through once before aliases are performed, so
175     they will apply.)</p>
176
177     <p>In particular, if you are creating an <code>Alias</code> to a
178     directory outside of your <code class="directive"><a href="../mod/core.html#documentroot">DocumentRoot</a></code>, you may need to explicitly
179     permit access to the target directory.</p>
180
181     <pre class="prettyprint lang-config">Alias "/image" "/ftp/pub/image"
182 &lt;Directory "/ftp/pub/image"&gt;
183     Require all granted
184 &lt;/Directory&gt;</pre>
185
186
187     <p>Any number slashes in the <var>URL-path</var> parameter 
188     matches any number of slashes in the requested URL-path.</p>
189
190     <p>If the <code class="directive">Alias</code> directive is used within a
191     <code class="directive"><a href="../mod/core.html#location">&lt;Location&gt;</a></code>
192     or <code class="directive"><a href="../mod/core.html#locationmatch">&lt;LocationMatch&gt;</a></code>
193     section the URL-path is omitted, and the file-path is interpreted
194     using <a href="../expr.html">expression syntax</a>.</p>
195
196     <pre class="prettyprint lang-config">&lt;Location "/image"&gt;
197     Alias "/ftp/pub/image"
198 &lt;/Location&gt;
199 &lt;LocationMatch "/error/(?&lt;NUMBER&gt;[0-9]+)"&gt;
200     Alias "/usr/local/apache/errors/%{env:MATCH_NUMBER}.html"
201 &lt;/LocationMatch&gt;</pre>
202
203
204
205 </div>
206 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
207 <div class="directive-section"><h2><a name="AliasMatch" id="AliasMatch">AliasMatch</a> <a name="aliasmatch" id="aliasmatch">Directive</a></h2>
208 <table class="directive">
209 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Maps URLs to filesystem locations using regular
210 expressions</td></tr>
211 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>AliasMatch <var>regex</var>
212 <var>file-path</var>|<var>directory-path</var></code></td></tr>
213 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
214 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
215 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_alias</td></tr>
216 </table>
217     <p>This directive is equivalent to <code class="directive"><a href="#alias">Alias</a></code>, but makes use of
218     <a class="glossarylink" href="../glossary.html#regex" title="see glossary">regular expressions</a>,
219     instead of simple prefix matching. The
220     supplied regular expression is matched against the URL-path, and
221     if it matches, the server will substitute any parenthesized
222     matches into the given string and use it as a filename. For
223     example, to activate the <code>/icons</code> directory, one might
224     use:</p>
225
226     <pre class="prettyprint lang-config">AliasMatch "^/icons(/|$)(.*)" "/usr/local/apache/icons$1$2"</pre>
227
228
229     <p>The full range of <a class="glossarylink" href="../glossary.html#regex" title="see glossary">regular expression</a>
230     power is available.  For example,
231     it is possible to construct an alias with case-insensitive
232     matching of the URL-path:</p>
233
234     <pre class="prettyprint lang-config">AliasMatch "(?i)^/image(.*)" "/ftp/pub/image$1"</pre>
235
236
237     <p>One subtle difference
238     between <code class="directive"><a href="#alias">Alias</a></code>
239     and <code class="directive"><a href="#aliasmatch">AliasMatch</a></code> is
240     that <code class="directive"><a href="#alias">Alias</a></code> will
241     automatically copy any additional part of the URI, past the part
242     that matched, onto the end of the file path on the right side,
243     while <code class="directive"><a href="#aliasmatch">AliasMatch</a></code> will
244     not.  This means that in almost all cases, you will want the
245     regular expression to match the entire request URI from beginning
246     to end, and to use substitution on the right side.</p>
247
248     <p>In other words, just changing
249     <code class="directive"><a href="#alias">Alias</a></code> to
250     <code class="directive"><a href="#aliasmatch">AliasMatch</a></code> will not
251     have the same effect.  At a minimum, you need to
252     add <code>^</code> to the beginning of the regular expression
253     and add <code>(.*)$</code> to the end, and add <code>$1</code> to
254     the end of the replacement.</p>
255
256     <p>For example, suppose you want to replace this with AliasMatch:</p>
257
258     <pre class="prettyprint lang-config">Alias "/image/" "/ftp/pub/image/"</pre>
259
260
261     <p>This is NOT equivalent - don't do this!  This will send all
262     requests that have /image/ anywhere in them to /ftp/pub/image/:</p>
263
264     <pre class="prettyprint lang-config">AliasMatch "/image/" "/ftp/pub/image/"</pre>
265
266
267     <p>This is what you need to get the same effect:</p>
268
269     <pre class="prettyprint lang-config">AliasMatch "^/image/(.*)$" "/ftp/pub/image/$1"</pre>
270
271
272     <p>Of course, there's no point in
273     using <code class="directive"><a href="#aliasmatch">AliasMatch</a></code>
274     where <code class="directive"><a href="#alias">Alias</a></code> would
275     work.  <code class="directive"><a href="#aliasmatch">AliasMatch</a></code> lets
276     you do more complicated things.  For example, you could
277     serve different kinds of files from different directories:</p>
278
279     <pre class="prettyprint lang-config">AliasMatch "^/image/(.*)\.jpg$" "/files/jpg.images/$1.jpg"<br />
280 AliasMatch "^/image/(.*)\.gif$" "/files/gif.images/$1.gif"</pre>
281
282
283     <p>Multiple leading slashes in the requested URL are discarded
284        by the server before directives from this module compares
285        against the requested URL-path.
286     </p>
287
288
289 </div>
290 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
291 <div class="directive-section"><h2><a name="Redirect" id="Redirect">Redirect</a> <a name="redirect" id="redirect">Directive</a></h2>
292 <table class="directive">
293 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sends an external redirect asking the client to fetch
294 a different URL</td></tr>
295 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>Redirect [<var>status</var>] [<var>URL-path</var>]
296 <var>URL</var></code></td></tr>
297 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
298 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
299 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
300 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_alias</td></tr>
301 </table>
302     <p>The Redirect directive maps an old URL into a new one by asking
303     the client to refetch the resource at the new location.</p>
304
305     <p>The old <em>URL-path</em> is a case-sensitive (%-decoded) path
306     beginning with a slash.  A relative path is not allowed.</p>
307
308     <p>The new <em>URL</em> may be either an absolute URL beginning
309     with a scheme and hostname, or a URL-path beginning with a slash.
310     In this latter case the scheme and hostname of the current server will
311     be added.</p>
312
313     <p>Then any request beginning with <em>URL-Path</em> will return a
314     redirect request to the client at the location of the target
315     <em>URL</em>.  Additional path information beyond the matched
316     <em>URL-Path</em> will be appended to the target URL.</p>
317
318     <pre class="prettyprint lang-config"># Redirect to a URL on a different host
319 Redirect "/service" "http://foo2.example.com/service"
320
321 # Redirect to a URL on the same host
322 Redirect "/one" "/two"</pre>
323
324
325     <p>If the client requests <code>http://example.com/service/foo.txt</code>,
326     it will be told to access
327     <code>http://foo2.example.com/service/foo.txt</code>
328         instead. This includes requests with <code>GET</code> parameters, such as
329     <code>http://example.com/service/foo.pl?q=23&amp;a=42</code>,
330     it will be redirected to
331     <code>http://foo2.example.com/service/foo.pl?q=23&amp;a=42</code>.
332         Note that <code>POST</code>s will be discarded.<br />
333         Only complete path segments are matched, so the above
334     example would not match a request for
335     <code>http://example.com/servicefoo.txt</code>. For more complex matching
336     using the <a href="../expr.html">expression syntax</a>, omit the URL-path
337     argument as described below. Alternatively, for matching using regular
338     expressions, see the <code class="directive"><a href="#redirectmatch">RedirectMatch</a></code> directive.</p>
339
340
341     <div class="note"><h3>Note</h3>
342     <p>Redirect directives take precedence over Alias and ScriptAlias
343     directives, irrespective of their ordering in the configuration
344     file. Redirect directives inside a Location take precedence over
345     Redirect and Alias directives with an URL-path.</p></div>
346
347     <p>If no <var>status</var> argument is given, the redirect will
348     be "temporary" (HTTP status 302). This indicates to the client
349     that the resource has moved temporarily. The <var>status</var>
350     argument can be used to return other HTTP status codes:</p>
351
352     <dl>
353       <dt>permanent</dt>
354
355       <dd>Returns a permanent redirect status (301) indicating that
356       the resource has moved permanently.</dd>
357
358       <dt>temp</dt>
359
360       <dd>Returns a temporary redirect status (302). This is the
361       default.</dd>
362
363       <dt>seeother</dt>
364
365       <dd>Returns a "See Other" status (303) indicating that the
366       resource has been replaced.</dd>
367
368       <dt>gone</dt>
369
370       <dd>Returns a "Gone" status (410) indicating that the
371       resource has been permanently removed. When this status is
372       used the <var>URL</var> argument should be omitted.</dd>
373     </dl>
374
375     <p>Other status codes can be returned by giving the numeric
376     status code as the value of <var>status</var>. If the status is
377     between 300 and 399, the <var>URL</var> argument must be present.
378     If the status is <em>not</em> between 300 and 399, the
379     <var>URL</var> argument must be omitted. The status must be a valid
380     HTTP status code, known to the Apache HTTP Server (see the function
381     <code>send_error_response</code> in http_protocol.c).</p>
382
383     <pre class="prettyprint lang-config">Redirect permanent "/one" "http://example.com/two"
384 Redirect 303 "/three" "http://example.com/other"</pre>
385
386
387     <p>If the <code class="directive">Redirect</code> directive is used within a
388     <code class="directive"><a href="../mod/core.html#location">&lt;Location&gt;</a></code>
389     or <code class="directive"><a href="../mod/core.html#locationmatch">&lt;LocationMatch&gt;</a></code>
390     section with the URL-path omitted, then the URL parameter will be
391     interpreted using <a href="../expr.html">expression syntax</a>.</p>
392
393     <pre class="prettyprint lang-config">&lt;Location "/one"&gt;
394     Redirect permanent "http://example.com/two"
395 &lt;/Location&gt;<br />
396 &lt;Location "/three"&gt;
397     Redirect 303 "http://example.com/other"
398 &lt;/Location&gt;<br />
399 &lt;LocationMatch "/error/(?&lt;NUMBER&gt;[0-9]+)"&gt;
400     Redirect permanent "http://example.com/errors/%{env:MATCH_NUMBER}.html"
401 &lt;/LocationMatch&gt;<br />
402     </pre>
403
404
405
406 </div>
407 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
408 <div class="directive-section"><h2><a name="RedirectMatch" id="RedirectMatch">RedirectMatch</a> <a name="redirectmatch" id="redirectmatch">Directive</a></h2>
409 <table class="directive">
410 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sends an external redirect based on a regular expression match
411 of the current URL</td></tr>
412 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RedirectMatch [<var>status</var>] <var>regex</var>
413 <var>URL</var></code></td></tr>
414 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
415 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
416 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
417 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_alias</td></tr>
418 </table>
419     <p>This directive is equivalent to <code class="directive"><a href="#redirect">Redirect</a></code>, but makes use of
420     <a class="glossarylink" href="../glossary.html#regex" title="see glossary">regular expressions</a>,
421     instead of simple prefix matching. The
422     supplied regular expression is matched against the URL-path, and
423     if it matches, the server will substitute any parenthesized
424     matches into the given string and use it as a filename. For
425     example, to redirect all GIF files to like-named JPEG files on
426     another server, one might use:</p>
427
428     <pre class="prettyprint lang-config">RedirectMatch "(.*)\.gif$" "http://other.example.com$1.jpg"</pre>
429
430
431     <p>The considerations related to the difference between
432     <code class="directive"><a href="#alias">Alias</a></code> and
433     <code class="directive"><a href="#aliasmatch">AliasMatch</a></code>
434     also apply to the difference between
435     <code class="directive"><a href="#redirect">Redirect</a></code> and
436     <code class="directive"><a href="#redirectmatch">RedirectMatch</a></code>.
437     See <code class="directive"><a href="#aliasmatch">AliasMatch</a></code> for
438     details.</p>
439
440
441
442 </div>
443 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
444 <div class="directive-section"><h2><a name="RedirectPermanent" id="RedirectPermanent">RedirectPermanent</a> <a name="redirectpermanent" id="redirectpermanent">Directive</a></h2>
445 <table class="directive">
446 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sends an external permanent redirect asking the client to fetch
447 a different URL</td></tr>
448 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RedirectPermanent <var>URL-path</var> <var>URL</var></code></td></tr>
449 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
450 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
451 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
452 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_alias</td></tr>
453 </table>
454     <p>This directive makes the client know that the Redirect is
455     permanent (status 301). Exactly equivalent to <code>Redirect
456     permanent</code>.</p>
457
458 </div>
459 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
460 <div class="directive-section"><h2><a name="RedirectTemp" id="RedirectTemp">RedirectTemp</a> <a name="redirecttemp" id="redirecttemp">Directive</a></h2>
461 <table class="directive">
462 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sends an external temporary redirect asking the client to fetch
463 a different URL</td></tr>
464 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RedirectTemp <var>URL-path</var> <var>URL</var></code></td></tr>
465 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
466 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
467 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
468 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_alias</td></tr>
469 </table>
470     <p>This directive makes the client know that the Redirect is
471     only temporary (status 302). Exactly equivalent to
472     <code>Redirect temp</code>.</p>
473
474 </div>
475 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
476 <div class="directive-section"><h2><a name="ScriptAlias" id="ScriptAlias">ScriptAlias</a> <a name="scriptalias" id="scriptalias">Directive</a></h2>
477 <table class="directive">
478 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Maps a URL to a filesystem location and designates the
479 target as a CGI script</td></tr>
480 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>ScriptAlias [<var>URL-path</var>]
481 <var>file-path</var>|<var>directory-path</var></code></td></tr>
482 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory</td></tr>
483 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
484 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_alias</td></tr>
485 </table>
486     <p>The <code class="directive">ScriptAlias</code> directive has the same
487     behavior as the <code class="directive"><a href="#alias">Alias</a></code>
488     directive, except that in addition it marks the target directory
489     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
490     (%-decoded) path beginning with <var>URL-path</var> will be mapped
491     to scripts beginning with the second argument, which is a full
492     pathname in the local filesystem.</p>
493
494     <pre class="prettyprint lang-config">ScriptAlias "/cgi-bin/" "/web/cgi-bin/"</pre>
495
496
497     <p>A request for <code>http://example.com/cgi-bin/foo</code> would cause the
498     server to run the script <code>/web/cgi-bin/foo</code>.  This configuration
499     is essentially equivalent to:</p>
500     <pre class="prettyprint lang-config">Alias "/cgi-bin/" "/web/cgi-bin/"
501 &lt;Location "/cgi-bin"&gt;
502     SetHandler cgi-script
503     Options +ExecCGI
504 &lt;/Location&gt;</pre>
505
506
507         <p><code class="directive">ScriptAlias</code> can also be used in conjunction with
508         a script or handler you have. For example:</p>
509
510         <pre class="prettyprint lang-config">ScriptAlias "/cgi-bin/" "/web/cgi-handler.pl"</pre>
511
512
513     <p>In this scenario all files requested in <code>/cgi-bin/</code> will be
514     handled by the file you have configured, this allows you to use your own custom
515     handler.  You may want to use this as a wrapper for CGI so that you can add
516     content, or some other bespoke action.</p>
517
518     <div class="warning">It is safer to avoid placing CGI scripts under the
519     <code class="directive"><a href="../mod/core.html#documentroot">DocumentRoot</a></code> in order to
520     avoid accidentally revealing their source code if the
521     configuration is ever changed.  The
522     <code class="directive">ScriptAlias</code> makes this easy by mapping a
523     URL and designating CGI scripts at the same time.  If you do
524     choose to place your CGI scripts in a directory already
525     accessible from the web, do not use
526     <code class="directive">ScriptAlias</code>.  Instead, use <code class="directive"><a href="../mod/core.html#directory">&lt;Directory&gt;</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:
527     <pre class="prettyprint lang-config">&lt;Directory "/usr/local/apache2/htdocs/cgi-bin"&gt;
528     SetHandler cgi-script
529     Options ExecCGI
530 &lt;/Directory&gt;</pre>
531
532     This is necessary since multiple <var>URL-paths</var> can map
533     to the same filesystem location, potentially bypassing the
534     <code class="directive">ScriptAlias</code> and revealing the source code
535     of the CGI scripts if they are not restricted by a
536     <code class="directive"><a href="../mod/core.html#directory">Directory</a></code> section.</div>
537
538     <p>If the <code class="directive">ScriptAlias</code> directive is used within
539     a <code class="directive"><a href="../mod/core.html#location">&lt;Location&gt;</a></code>
540     or <code class="directive"><a href="../mod/core.html#locationmatch">&lt;LocationMatch&gt;</a></code>
541     section with the URL-path omitted, then the URL parameter will be
542     interpreted using <a href="../expr.html">expression syntax</a>.</p>
543
544     <pre class="prettyprint lang-config">&lt;Location "/cgi-bin"&gt;
545     ScriptAlias "/web/cgi-bin/"
546 &lt;/Location&gt;
547 &lt;LocationMatch "/cgi-bin/errors/(?&lt;NUMBER&gt;[0-9]+)"&gt;
548     ScriptAlias "/web/cgi-bin/errors/%{env:MATCH_NUMBER}.cgi"
549 &lt;/LocationMatch&gt;<br />
550     </pre>
551
552
553
554 <h3>See also</h3>
555 <ul>
556 <li><a href="../howto/cgi.html">CGI Tutorial</a></li>
557 </ul>
558 </div>
559 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
560 <div class="directive-section"><h2><a name="ScriptAliasMatch" id="ScriptAliasMatch">ScriptAliasMatch</a> <a name="scriptaliasmatch" id="scriptaliasmatch">Directive</a></h2>
561 <table class="directive">
562 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Maps a URL to a filesystem location using a regular expression
563 and designates the target as a CGI script</td></tr>
564 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>ScriptAliasMatch <var>regex</var>
565 <var>file-path</var>|<var>directory-path</var></code></td></tr>
566 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
567 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
568 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_alias</td></tr>
569 </table>
570     <p>This directive is equivalent to <code class="directive"><a href="#scriptalias">ScriptAlias</a></code>, but makes use of
571     <a class="glossarylink" href="../glossary.html#regex" title="see glossary">regular expressions</a>,
572     instead of simple prefix matching. The
573     supplied regular expression is matched against the URL-path,
574     and if it matches, the server will substitute any parenthesized
575     matches into the given string and use it as a filename. For
576     example, to activate the standard <code>/cgi-bin</code>, one
577     might use:</p>
578
579     <pre class="prettyprint lang-config">ScriptAliasMatch "^/cgi-bin(.*)" "/usr/local/apache/cgi-bin$1"</pre>
580
581
582     <p>As for AliasMatch, the full range of <a class="glossarylink" href="../glossary.html#rexex" title="see glossary">regular
583     expression</a> power is available.
584     For example, it is possible to construct an alias with case-insensitive
585     matching of the URL-path:</p>
586
587     <pre class="prettyprint lang-config">ScriptAliasMatch "(?i)^/cgi-bin(.*)" "/usr/local/apache/cgi-bin$1"</pre>
588
589
590     <p>The considerations related to the difference between
591     <code class="directive"><a href="#alias">Alias</a></code> and
592     <code class="directive"><a href="#aliasmatch">AliasMatch</a></code>
593     also apply to the difference between
594     <code class="directive"><a href="#scriptalias">ScriptAlias</a></code> and
595     <code class="directive"><a href="#scriptaliasmatch">ScriptAliasMatch</a></code>.
596     See <code class="directive"><a href="#aliasmatch">AliasMatch</a></code> for
597     details.</p>
598
599
600 </div>
601 </div>
602 <div class="bottomlang">
603 <p><span>Available Languages: </span><a href="../en/mod/mod_alias.html" title="English">&nbsp;en&nbsp;</a> |
604 <a href="../fr/mod/mod_alias.html" hreflang="fr" rel="alternate" title="Français">&nbsp;fr&nbsp;</a> |
605 <a href="../ja/mod/mod_alias.html" hreflang="ja" rel="alternate" title="Japanese">&nbsp;ja&nbsp;</a> |
606 <a href="../ko/mod/mod_alias.html" hreflang="ko" rel="alternate" title="Korean">&nbsp;ko&nbsp;</a> |
607 <a href="../tr/mod/mod_alias.html" hreflang="tr" rel="alternate" title="Türkçe">&nbsp;tr&nbsp;</a></p>
608 </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&amp;A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed again 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 Freenode, or sent to our <a href="http://httpd.apache.org/lists.html">mailing lists</a>.</div>
609 <script type="text/javascript"><!--//--><![CDATA[//><!--
610 var comments_shortname = 'httpd';
611 var comments_identifier = 'http://httpd.apache.org/docs/trunk/mod/mod_alias.html';
612 (function(w, d) {
613     if (w.location.hostname.toLowerCase() == "httpd.apache.org") {
614         d.write('<div id="comments_thread"><\/div>');
615         var s = d.createElement('script');
616         s.type = 'text/javascript';
617         s.async = true;
618         s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
619         (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
620     }
621     else {
622         d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>');
623     }
624 })(window, document);
625 //--><!]]></script></div><div id="footer">
626 <p class="apache">Copyright 2015 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>
627 <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[//><!--
628 if (typeof(prettyPrint) !== 'undefined') {
629     prettyPrint();
630 }
631 //--><!]]></script>
632 </body></html>