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.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/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.4</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.4</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">Alias /foo/bar /baz
101Alias /foo /gaq</pre>
102
103
104    <p>But if the above two directives were reversed in order, the
105    <code>/foo</code> <code class="directive"><a href="#alias">Alias</a></code>
106    would always match before the <code>/foo/bar</code> <code class="directive"><a href="#alias">Alias</a></code>, so the latter directive would be
107    ignored.</p>
108
109</div>
110<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
111<div class="directive-section"><h2><a name="Alias" id="Alias">Alias</a> <a name="alias" id="alias">Directive</a></h2>
112<table class="directive">
113<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Maps URLs to filesystem locations</td></tr>
114<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>Alias <var>URL-path</var>
115<var>file-path</var>|<var>directory-path</var></code></td></tr>
116<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
117<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
118<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_alias</td></tr>
119</table>
120
121    <p>The <code class="directive">Alias</code> directive allows documents to
122    be stored in the local filesystem other than under the
123    <code class="directive"><a href="/mod/core.html#documentroot">DocumentRoot</a></code>. URLs with a
124    (%-decoded) path beginning with <var>URL-path</var> will be mapped
125    to local files beginning with <var>directory-path</var>.  The
126    <var>URL-path</var> is case-sensitive, even on case-insensitive
127    file systems.</p>
128
129    <pre class="prettyprint lang-config">Alias /image /ftp/pub/image</pre>
130
131
132    <p>A request for <code>http://example.com/image/foo.gif</code> would cause
133    the server to return the file <code>/ftp/pub/image/foo.gif</code>.  Only
134    complete path segments are matched, so the above alias would not match a
135    request for <code>http://example.com/imagefoo.gif</code>.  For more complex
136    matching using regular expressions, see the <code class="directive"><a href="#aliasmatch">AliasMatch</a></code> directive.</p>
137
138    <p>Note that if you include a trailing / on the
139    <var>URL-path</var> then the server will require a trailing / in
140    order to expand the alias. That is, if you use</p>
141
142    <pre class="prettyprint lang-config">Alias /icons/ /usr/local/apache/icons/</pre>
143
144
145    <p>then the url <code>/icons</code> will not be aliased, as it lacks
146    that trailing /. Likewise, if you omit the slash on the
147    <var>URL-path</var> then you must also omit it from the
148    <var>file-path</var>.</p>
149
150    <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
151    cover the <em>destination</em> of aliases.  Aliasing occurs before
152    <code class="directive"><a href="/mod/core.html#directory">&lt;Directory&gt;</a></code> sections
153    are checked, so only the destination of aliases are affected.
154    (Note however <code class="directive"><a href="/mod/core.html#location">&lt;Location&gt;</a></code>
155    sections are run through once before aliases are performed, so
156    they will apply.)</p>
157
158    <p>In particular, if you are creating an <code>Alias</code> to a
159    directory outside of your <code class="directive"><a href="/mod/core.html#documentroot">DocumentRoot</a></code>, you may need to explicitly
160    permit access to the target directory.</p>
161
162    <pre class="prettyprint lang-config">Alias /image /ftp/pub/image
163&lt;Directory /ftp/pub/image&gt;
164    Require all granted
165&lt;/Directory&gt;</pre>
166
167
168    <p>Any number slashes in the <var>URL-path</var> parameter 
169    matches any number of slashes in the requested URL-path.</p>
170
171
172</div>
173<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
174<div class="directive-section"><h2><a name="AliasMatch" id="AliasMatch">AliasMatch</a> <a name="aliasmatch" id="aliasmatch">Directive</a></h2>
175<table class="directive">
176<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Maps URLs to filesystem locations using regular
177expressions</td></tr>
178<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>AliasMatch <var>regex</var>
179<var>file-path</var>|<var>directory-path</var></code></td></tr>
180<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
181<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
182<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_alias</td></tr>
183</table>
184    <p>This directive is equivalent to <code class="directive"><a href="#alias">Alias</a></code>, but makes use of
185    <a class="glossarylink" href="/glossary.html#regex" title="see glossary">regular expressions</a>,
186    instead of simple prefix matching. The
187    supplied regular expression is matched against the URL-path, and
188    if it matches, the server will substitute any parenthesized
189    matches into the given string and use it as a filename. For
190    example, to activate the <code>/icons</code> directory, one might
191    use:</p>
192
193    <pre class="prettyprint lang-config">AliasMatch ^/icons(.*) /usr/local/apache/icons$1</pre>
194
195
196    <p>The full range of <a class="glossarylink" href="/glossary.html#regex" title="see glossary">regular expression</a>
197    power is available.  For example,
198    it is possible to construct an alias with case-insensitive
199    matching of the URL-path:</p>
200
201    <pre class="prettyprint lang-config">AliasMatch (?i)^/image(.*) /ftp/pub/image$1</pre>
202
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    <pre class="prettyprint lang-config">Alias /image/ /ftp/pub/image/</pre>
226
227
228    <p>This is NOT equivalent - don't do this!  This will send all
229    requests that have /image/ anywhere in them to /ftp/pub/image/:</p>
230
231    <pre class="prettyprint lang-config">AliasMatch /image/ /ftp/pub/image/</pre>
232
233
234    <p>This is what you need to get the same effect:</p>
235
236    <pre class="prettyprint lang-config">AliasMatch ^/image/(.*)$ /ftp/pub/image/$1</pre>
237
238
239    <p>Of course, there's no point in
240    using <code class="directive"><a href="#aliasmatch">AliasMatch</a></code>
241    where <code class="directive"><a href="#alias">Alias</a></code> would
242    work.  <code class="directive"><a href="#aliasmatch">AliasMatch</a></code> lets
243    you do more complicated things.  For example, you could
244    serve different kinds of files from different directories:</p>
245
246    <pre class="prettyprint lang-config">      AliasMatch ^/image/(.*)\.jpg$ /files/jpg.images/$1.jpg<br />
247      AliasMatch ^/image/(.*)\.gif$ /files/gif.images/$1.gif</pre>
248
249
250    <p>Multiple leading slashes in the requested URL are discarded
251       by the server before directives from this module compares
252       against the requested URL-path.
253    </p>
254
255
256</div>
257<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
258<div class="directive-section"><h2><a name="Redirect" id="Redirect">Redirect</a> <a name="redirect" id="redirect">Directive</a></h2>
259<table class="directive">
260<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sends an external redirect asking the client to fetch
261a different URL</td></tr>
262<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>Redirect [<var>status</var>] <var>URL-path</var>
263<var>URL</var></code></td></tr>
264<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
265<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
266<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
267<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_alias</td></tr>
268</table>
269    <p>The Redirect directive maps an old URL into a new one by asking
270    the client to refetch the resource at the new location.</p>
271
272    <p>The old <em>URL-path</em> is a case-sensitive (%-decoded) path
273    beginning with a slash.  A relative path is not allowed.</p>
274
275    <p>The new <em>URL</em> may be either an absolute URL beginning
276    with a scheme and hostname, or a URL-path beginning with a slash.
277    In this latter case the scheme and hostname of the current server will
278    be added.</p>
279
280    <p>Then any request beginning with <em>URL-Path</em> will return a
281    redirect request to the client at the location of the target
282    <em>URL</em>.  Additional path information beyond the matched
283    <em>URL-Path</em> will be appended to the target URL.</p>
284
285    <pre class="prettyprint lang-config"># Redirect to a URL on a different host
286Redirect /service http://foo2.example.com/service
287
288# Redirect to a URL on the same host
289Redirect /one /two</pre>
290
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&a=42</code>,
297    it will be redirected to
298    <code>http://foo2.example.com/service/foo.pl?q=23&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    If the status is <em>not</em> between 300 and 399, the
343    <var>URL</var> argument must be omitted. The status must be a valid
344    HTTP status code, known to the Apache HTTP Server (see the function
345    <code>send_error_response</code> in http_protocol.c).</p>
346
347    <pre class="prettyprint lang-config">Redirect permanent /one http://example.com/two
348Redirect 303 /three http://example.com/other</pre>
349
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
357of 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    <pre class="prettyprint lang-config">RedirectMatch (.*)\.gif$ http://other.example.com$1.jpg</pre>
375
376
377    <p>The considerations related to the difference between
378    <code class="directive"><a href="#alias">Alias</a></code> and
379    <code class="directive"><a href="#aliasmatch">AliasMatch</a></code>
380    also apply to the difference between
381    <code class="directive"><a href="#redirect">Redirect</a></code> and
382    <code class="directive"><a href="#redirectmatch">RedirectMatch</a></code>.
383    See <code class="directive"><a href="#aliasmatch">AliasMatch</a></code> for
384    details.</p>
385
386
387
388</div>
389<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
390<div class="directive-section"><h2><a name="RedirectPermanent" id="RedirectPermanent">RedirectPermanent</a> <a name="redirectpermanent" id="redirectpermanent">Directive</a></h2>
391<table class="directive">
392<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sends an external permanent redirect asking the client to fetch
393a different URL</td></tr>
394<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RedirectPermanent <var>URL-path</var> <var>URL</var></code></td></tr>
395<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
396<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
397<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
398<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_alias</td></tr>
399</table>
400    <p>This directive makes the client know that the Redirect is
401    permanent (status 301). Exactly equivalent to <code>Redirect
402    permanent</code>.</p>
403
404</div>
405<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
406<div class="directive-section"><h2><a name="RedirectTemp" id="RedirectTemp">RedirectTemp</a> <a name="redirecttemp" id="redirecttemp">Directive</a></h2>
407<table class="directive">
408<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sends an external temporary redirect asking the client to fetch
409a different URL</td></tr>
410<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RedirectTemp <var>URL-path</var> <var>URL</var></code></td></tr>
411<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
412<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
413<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
414<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_alias</td></tr>
415</table>
416    <p>This directive makes the client know that the Redirect is
417    only temporary (status 302). Exactly equivalent to
418    <code>Redirect temp</code>.</p>
419
420</div>
421<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
422<div class="directive-section"><h2><a name="ScriptAlias" id="ScriptAlias">ScriptAlias</a> <a name="scriptalias" id="scriptalias">Directive</a></h2>
423<table class="directive">
424<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Maps a URL to a filesystem location and designates the
425target as a CGI script</td></tr>
426<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>ScriptAlias <var>URL-path</var>
427<var>file-path</var>|<var>directory-path</var></code></td></tr>
428<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
429<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
430<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_alias</td></tr>
431</table>
432    <p>The <code class="directive">ScriptAlias</code> directive has the same
433    behavior as the <code class="directive"><a href="#alias">Alias</a></code>
434    directive, except that in addition it marks the target directory
435    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
436    (%-decoded) path beginning with <var>URL-path</var> will be mapped
437    to scripts beginning with the second argument, which is a full
438    pathname in the local filesystem.</p>
439
440    <pre class="prettyprint lang-config">ScriptAlias /cgi-bin/ /web/cgi-bin/</pre>
441
442
443    <p>A request for <code>http://example.com/cgi-bin/foo</code> would cause the
444    server to run the script <code>/web/cgi-bin/foo</code>.  This configuration
445    is essentially equivalent to:</p>
446    <pre class="prettyprint lang-config">Alias /cgi-bin/ /web/cgi-bin/
447&lt;Location /cgi-bin &gt;
448    SetHandler cgi-script
449    Options +ExecCGI
450&lt;/Location&gt;</pre>
451
452
453	<p><code class="directive">ScriptAlias</code> can also be used in conjunction with
454	a script or handler you have. For example:</p>
455
456	<pre class="prettyprint lang-config">ScriptAlias /cgi-bin/ /web/cgi-handler.pl</pre>
457
458
459    <p>In this scenario all files requested in <code>/cgi-bin/</code> will be
460    handled by the file you have configured, this allows you to use your own custom
461    handler.  You may want to use this as a wrapper for CGI so that you can add
462    content, or some other bespoke action.</p>
463
464    <div class="warning">It is safer to avoid placing CGI scripts under the
465    <code class="directive"><a href="/mod/core.html#documentroot">DocumentRoot</a></code> in order to
466    avoid accidentally revealing their source code if the
467    configuration is ever changed.  The
468    <code class="directive">ScriptAlias</code> makes this easy by mapping a
469    URL and designating CGI scripts at the same time.  If you do
470    choose to place your CGI scripts in a directory already
471    accessible from the web, do not use
472    <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:
473    <pre class="prettyprint lang-config">&lt;Directory /usr/local/apache2/htdocs/cgi-bin &gt;
474    SetHandler cgi-script
475    Options ExecCGI
476&lt;/Directory&gt;</pre>
477
478    This is necessary since multiple <var>URL-paths</var> can map
479    to the same filesystem location, potentially bypassing the
480    <code class="directive">ScriptAlias</code> and revealing the source code
481    of the CGI scripts if they are not restricted by a
482    <code class="directive"><a href="/mod/core.html#directory">Directory</a></code> section.</div>
483
484
485<h3>See also</h3>
486<ul>
487<li><a href="/howto/cgi.html">CGI Tutorial</a></li>
488</ul>
489</div>
490<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
491<div class="directive-section"><h2><a name="ScriptAliasMatch" id="ScriptAliasMatch">ScriptAliasMatch</a> <a name="scriptaliasmatch" id="scriptaliasmatch">Directive</a></h2>
492<table class="directive">
493<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Maps a URL to a filesystem location using a regular expression
494and designates the target as a CGI script</td></tr>
495<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>ScriptAliasMatch <var>regex</var>
496<var>file-path</var>|<var>directory-path</var></code></td></tr>
497<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
498<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
499<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_alias</td></tr>
500</table>
501    <p>This directive is equivalent to <code class="directive"><a href="#scriptalias">ScriptAlias</a></code>, but makes use of
502    <a class="glossarylink" href="/glossary.html#regex" title="see glossary">regular expressions</a>,
503    instead of simple prefix matching. The
504    supplied regular expression is matched against the URL-path,
505    and if it matches, the server will substitute any parenthesized
506    matches into the given string and use it as a filename. For
507    example, to activate the standard <code>/cgi-bin</code>, one
508    might use:</p>
509
510    <pre class="prettyprint lang-config">ScriptAliasMatch ^/cgi-bin(.*) /usr/local/apache/cgi-bin$1</pre>
511
512
513    <p>As for AliasMatch, the full range of <a class="glossarylink" href="/glossary.html#rexex" title="see glossary">regular
514    expression</a> power is available.
515    For example, it is possible to construct an alias with case-insensitive
516    matching of the URL-path:</p>
517
518    <pre class="prettyprint lang-config">ScriptAliasMatch (?i)^/cgi-bin(.*) /usr/local/apache/cgi-bin$1</pre>
519
520
521    <p>The considerations related to the difference between
522    <code class="directive"><a href="#alias">Alias</a></code> and
523    <code class="directive"><a href="#aliasmatch">AliasMatch</a></code>
524    also apply to the difference between
525    <code class="directive"><a href="#scriptalias">ScriptAlias</a></code> and
526    <code class="directive"><a href="#scriptaliasmatch">ScriptAliasMatch</a></code>.
527    See <code class="directive"><a href="#aliasmatch">AliasMatch</a></code> for
528    details.</p>
529
530
531</div>
532</div>
533<div class="bottomlang">
534<p><span>Available Languages: </span><a href="/en/mod/mod_alias.html" title="English">&nbsp;en&nbsp;</a> |
535<a href="/fr/mod/mod_alias.html" hreflang="fr" rel="alternate" title="Fran�ais">&nbsp;fr&nbsp;</a> |
536<a href="/ja/mod/mod_alias.html" hreflang="ja" rel="alternate" title="Japanese">&nbsp;ja&nbsp;</a> |
537<a href="/ko/mod/mod_alias.html" hreflang="ko" rel="alternate" title="Korean">&nbsp;ko&nbsp;</a> |
538<a href="/tr/mod/mod_alias.html" hreflang="tr" rel="alternate" title="T�rk�e">&nbsp;tr&nbsp;</a></p>
539</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>
540<script type="text/javascript"><!--//--><![CDATA[//><!--
541var comments_shortname = 'httpd';
542var comments_identifier = 'http://httpd.apache.org/docs/2.4/mod/mod_alias.html';
543(function(w, d) {
544    if (w.location.hostname.toLowerCase() == "httpd.apache.org") {
545        d.write('<div id="comments_thread"><\/div>');
546        var s = d.createElement('script');
547        s.type = 'text/javascript';
548        s.async = true;
549        s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
550        (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
551    }
552    else { 
553        d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>');
554    }
555})(window, document);
556//--><!]]></script></div><div id="footer">
557<p class="apache">Copyright 2014 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>
558<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[//><!--
559if (typeof(prettyPrint) !== 'undefined') {
560    prettyPrint();
561}
562//--><!]]></script>
563</body></html>