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