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