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.2</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.2</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="/ja/mod/mod_alias.html" hreflang="ja" rel="alternate" title="Japanese">&nbsp;ja&nbsp;</a> |
29<a href="/ko/mod/mod_alias.html" hreflang="ko" rel="alternate" title="Korean">&nbsp;ko&nbsp;</a> |
30<a href="/tr/mod/mod_alias.html" hreflang="tr" rel="alternate" title="T�rk�e">&nbsp;tr&nbsp;</a></p>
31</div>
32<table class="module"><tr><th><a href="module-dict.html#Description">Description:</a></th><td>Provides for mapping different parts of the host
33    filesystem in the document tree and for URL redirection</td></tr>
34<tr><th><a href="module-dict.html#Status">Status:</a></th><td>Base</td></tr>
35<tr><th><a href="module-dict.html#ModuleIdentifier">Module�Identifier:</a></th><td>alias_module</td></tr>
36<tr><th><a href="module-dict.html#SourceFile">Source�File:</a></th><td>mod_alias.c</td></tr></table>
37<h3>Summary</h3>
38
39    <p>The directives contained in this module allow for manipulation
40    and control of URLs as requests arrive at the server. The
41    <code class="directive"><a href="#alias">Alias</a></code> and <code class="directive"><a href="#scriptalias">ScriptAlias</a></code> directives are used to
42    map between URLs and filesystem paths.  This allows for content
43    which is not directly under the <code class="directive"><a href="/mod/core.html#documentroot">DocumentRoot</a></code> served as part of the web
44    document tree. The <code class="directive"><a href="#scriptalias">ScriptAlias</a></code> directive has the
45    additional effect of marking the target directory as containing
46    only CGI scripts.</p>
47
48    <p>The <code class="directive"><a href="#redirect">Redirect</a></code>
49    directives are used to instruct clients to make a new request with
50    a different URL. They are often used when a resource has moved to
51    a new location.</p>
52
53    <p><code class="module"><a href="/mod/mod_alias.html">mod_alias</a></code> is designed to handle simple URL
54    manipulation tasks.  For more complicated tasks such as
55    manipulating the query string, use the tools provided by
56    <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code>.</p>
57
58</div>
59<div id="quickview"><h3 class="directives">Directives</h3>
60<ul id="toc">
61<li><img alt="" src="/images/down.gif" /> <a href="#alias">Alias</a></li>
62<li><img alt="" src="/images/down.gif" /> <a href="#aliasmatch">AliasMatch</a></li>
63<li><img alt="" src="/images/down.gif" /> <a href="#redirect">Redirect</a></li>
64<li><img alt="" src="/images/down.gif" /> <a href="#redirectmatch">RedirectMatch</a></li>
65<li><img alt="" src="/images/down.gif" /> <a href="#redirectpermanent">RedirectPermanent</a></li>
66<li><img alt="" src="/images/down.gif" /> <a href="#redirecttemp">RedirectTemp</a></li>
67<li><img alt="" src="/images/down.gif" /> <a href="#scriptalias">ScriptAlias</a></li>
68<li><img alt="" src="/images/down.gif" /> <a href="#scriptaliasmatch">ScriptAliasMatch</a></li>
69</ul>
70<h3>Topics</h3>
71<ul id="topics">
72<li><img alt="" src="/images/down.gif" /> <a href="#order">Order of Processing</a></li>
73</ul><h3>See also</h3>
74<ul class="seealso">
75<li><code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code></li>
76<li><a href="/URLmapping.html">Mapping URLs to the filesystem</a></li>
77</ul><ul class="seealso"><li><a href="#comments_section">Comments</a></li></ul></div>
78<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
79<div class="section">
80<h2><a name="order" id="order">Order of Processing</a></h2>
81
82    <p>Aliases and Redirects occurring in different contexts are processed
83    like other directives according to standard <a href="/sections.html#mergin">merging rules</a>.  But when multiple
84    Aliases or Redirects occur in the same context (for example, in the
85    same <code class="directive"><a href="/mod/core.html#virtualhost">&lt;VirtualHost&gt;</a></code>
86    section) they are processed in a particular order.</p>
87
88    <p>First, all Redirects are processed before Aliases are processed,
89    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
90    applied.  Second, the Aliases and Redirects are processed in the order
91    they appear in the configuration files, with the first match taking
92    precedence.</p>
93
94    <p>For this reason, when two or more of these directives apply to the
95    same sub-path, you must list the most specific path first in order for
96    all the directives to have an effect.  For example, the following
97    configuration will work as expected:</p>
98
99    <div class="example"><p><code>
100    Alias /foo/bar /baz<br />
101    Alias /foo /gaq
102    </code></p></div>
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    <div class="example"><h3>Example:</h3><p><code>
130      Alias /image /ftp/pub/image
131    </code></p></div>
132
133    <p>A request for <code>http://example.com/image/foo.gif</code> would cause
134    the server to return the file <code>/ftp/pub/image/foo.gif</code>.  Only
135    complete path segments are matched, so the above alias would not match a
136    request for <code>http://example.com/imagefoo.gif</code>.  For more complex
137    matching using regular expressions, see the <code class="directive"><a href="#aliasmatch">AliasMatch</a></code> directive.</p>
138
139    <p>Note that if you include a trailing / on the
140    <var>URL-path</var> then the server will require a trailing / in
141    order to expand the alias. That is, if you use</p>
142
143    <dl><dd><code>Alias /icons/ /usr/local/apache/icons/</code></dd></dl>
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    <div class="example"><h3>Example:</h3><p><code>
163        Alias /image /ftp/pub/image<br />
164        &lt;Directory /ftp/pub/image&gt;<br />
165        <span class="indent">
166            Order allow,deny<br />
167            Allow from all<br />
168        </span>
169        &lt;/Directory&gt;
170    </code></p></div>
171
172    <p>Any number of slashes in the <var>URL-path</var> parameter
173    matches any number of slashes in the requested URL-path.</p>
174
175
176</div>
177<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
178<div class="directive-section"><h2><a name="AliasMatch" id="AliasMatch">AliasMatch</a> <a name="aliasmatch" id="aliasmatch">Directive</a></h2>
179<table class="directive">
180<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Maps URLs to filesystem locations using regular
181expressions</td></tr>
182<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>AliasMatch <var>regex</var>
183<var>file-path</var>|<var>directory-path</var></code></td></tr>
184<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
185<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
186<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_alias</td></tr>
187</table>
188    <p>This directive is equivalent to <code class="directive"><a href="#alias">Alias</a></code>, but makes use of
189    <a class="glossarylink" href="/glossary.html#regex" title="see glossary">regular expressions</a>,
190    instead of simple prefix matching. The
191    supplied regular expression is matched against the URL-path, and
192    if it matches, the server will substitute any parenthesized
193    matches into the given string and use it as a filename. For
194    example, to activate the <code>/icons</code> directory, one might
195    use:</p>
196
197    <div class="example"><p><code>
198      AliasMatch ^/icons(.*) /usr/local/apache/icons$1
199    </code></p></div>
200
201    <p>The full range of <a class="glossarylink" href="/glossary.html#regex" title="see glossary">regular expression</a>
202    power is available.  For example,
203    it is possible to construct an alias with case-insensitive
204    matching of the URL-path:</p>
205
206    <div class="example"><p><code>
207      AliasMatch (?i)^/image(.*) /ftp/pub/image$1
208    </code></p></div>
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    <div class="example"><p><code>
232      Alias /image/ /ftp/pub/image/
233    </code></p></div>
234
235    <p>This is NOT equivalent - don't do this!  This will send all
236    requests that have /image/ anywhere in them to /ftp/pub/image/:</p>
237
238    <div class="example"><p><code>
239      AliasMatch /image/ /ftp/pub/image/
240    </code></p></div>
241
242    <p>This is what you need to get the same effect:</p>
243
244    <div class="example"><p><code>
245      AliasMatch ^/image/(.*)$ /ftp/pub/image/$1
246    </code></p></div>
247
248    <p>Of course, there's no point in
249    using <code class="directive"><a href="#aliasmatch">AliasMatch</a></code>
250    where <code class="directive"><a href="#alias">Alias</a></code> would
251    work.  <code class="directive"><a href="#aliasmatch">AliasMatch</a></code> lets
252    you do more complicated things.  For example, you could
253    serve different kinds of files from different directories:</p>
254
255    <div class="example"><p><code>
256      AliasMatch ^/image/(.*)\.jpg$ /files/jpg.images/$1.jpg<br />
257      AliasMatch ^/image/(.*)\.gif$ /files/gif.images/$1.gif
258    </code></p></div>
259
260    <p>Multiple leading slashes in the requested URL are discarded
261       by the server before directives from this module compares
262       against the requested URL-path.
263    </p>
264
265
266</div>
267<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
268<div class="directive-section"><h2><a name="Redirect" id="Redirect">Redirect</a> <a name="redirect" id="redirect">Directive</a></h2>
269<table class="directive">
270<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sends an external redirect asking the client to fetch
271a different URL</td></tr>
272<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>Redirect [<var>status</var>] <var>URL-path</var>
273<var>URL</var></code></td></tr>
274<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
275<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
276<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
277<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_alias</td></tr>
278<tr><th><a href="directive-dict.html#Compatibility">Compatibility:</a></th><td>Support for specifying a URL-path as the final argument was 
279added in Apache HTTP Server 2.2.6</td></tr>
280</table>
281    <p>The Redirect directive maps an old URL into a new one by asking
282    the client to refetch the resource at the new location.</p>
283
284    <p>The old <em>URL-path</em> is a case-sensitive (%-decoded) path
285    beginning with a slash.  A relative path is not allowed.  The new
286    <em>URL</em> should be an absolute URL beginning with a scheme and
287    hostname.  In Apache HTTP Server 2.2.6 and later, a URL-path beginning 
288    with a slash may also be used, in which case the scheme and hostname 
289    of the current server will be added.</p>
290
291    <p>Then any request beginning with <em>URL-path</em> will return a
292    redirect request to the client at the location of the target
293    <em>URL</em>.  Additional path information beyond the matched
294    <em>URL-path</em> will be appended to the target URL.</p>
295
296    <div class="example"><h3>Example:</h3><p><code>
297      Redirect /service http://foo2.example.com/service
298    </code></p></div>
299
300    <p>If the client requests <code>http://example.com/service/foo.txt</code>,
301    it will be told to access
302    <code>http://foo2.example.com/service/foo.txt</code>
303    instead.  Only complete path segments are matched, so the above
304    example would not match a request for
305    <code>http://example.com/servicefoo.txt</code>.  For more complex matching
306    using regular expressions, see the <code class="directive"><a href="#redirectmatch">RedirectMatch</a></code> directive.</p>
307
308
309    <div class="note"><h3>Note</h3>
310    <p>Redirect directives take precedence over
311    Alias and ScriptAlias directives, irrespective of their ordering in
312    the configuration file.</p></div>
313
314    <p>If no <var>status</var> argument is given, the redirect will
315    be "temporary" (HTTP status 302). This indicates to the client
316    that the resource has moved temporarily. The <var>status</var>
317    argument can be used to return other HTTP status codes:</p>
318
319    <dl>
320      <dt>permanent</dt>
321
322      <dd>Returns a permanent redirect status (301) indicating that
323      the resource has moved permanently.</dd>
324
325      <dt>temp</dt>
326
327      <dd>Returns a temporary redirect status (302). This is the
328      default.</dd>
329
330      <dt>seeother</dt>
331
332      <dd>Returns a "See Other" status (303) indicating that the
333      resource has been replaced.</dd>
334
335      <dt>gone</dt>
336
337      <dd>Returns a "Gone" status (410) indicating that the
338      resource has been permanently removed. When this status is
339      used the <var>URL</var> argument should be omitted.</dd>
340    </dl>
341
342    <p>Other status codes can be returned by giving the numeric
343    status code as the value of <var>status</var>. If the status is
344    between 300 and 399, the <var>URL</var> argument must be present,
345    otherwise it must be omitted. Note that the status must be
346    known to the Apache code (see the function
347    <code>send_error_response</code> in http_protocol.c).</p>
348
349    <div class="example"><h3>Example:</h3><p><code>
350      Redirect permanent /one http://example.com/two<br />
351      Redirect 303 /three http://example.com/other
352    </code></p></div>
353
354
355</div>
356<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
357<div class="directive-section"><h2><a name="RedirectMatch" id="RedirectMatch">RedirectMatch</a> <a name="redirectmatch" id="redirectmatch">Directive</a></h2>
358<table class="directive">
359<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sends an external redirect based on a regular expression match
360of the current URL</td></tr>
361<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RedirectMatch [<var>status</var>] <var>regex</var>
362<var>URL</var></code></td></tr>
363<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
364<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
365<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
366<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_alias</td></tr>
367</table>
368    <p>This directive is equivalent to <code class="directive"><a href="#redirect">Redirect</a></code>, but makes use of
369    <a class="glossarylink" href="/glossary.html#regex" title="see glossary">regular expressions</a>,
370    instead of simple prefix matching. The
371    supplied regular expression is matched against the URL-path, and
372    if it matches, the server will substitute any parenthesized
373    matches into the given string and use it as a filename. For
374    example, to redirect all GIF files to like-named JPEG files on
375    another server, one might use:</p>
376
377    <div class="example"><p><code>
378      RedirectMatch (.*)\.gif$ http://www.anotherserver.com$1.jpg
379    </code></p></div>
380
381</div>
382<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
383<div class="directive-section"><h2><a name="RedirectPermanent" id="RedirectPermanent">RedirectPermanent</a> <a name="redirectpermanent" id="redirectpermanent">Directive</a></h2>
384<table class="directive">
385<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sends an external permanent redirect asking the client to fetch
386a different URL</td></tr>
387<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RedirectPermanent <var>URL-path</var> <var>URL</var></code></td></tr>
388<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
389<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
390<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
391<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_alias</td></tr>
392</table>
393    <p>This directive makes the client know that the Redirect is
394    permanent (status 301). Exactly equivalent to <code>Redirect
395    permanent</code>.</p>
396
397</div>
398<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
399<div class="directive-section"><h2><a name="RedirectTemp" id="RedirectTemp">RedirectTemp</a> <a name="redirecttemp" id="redirecttemp">Directive</a></h2>
400<table class="directive">
401<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sends an external temporary redirect asking the client to fetch
402a different URL</td></tr>
403<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>RedirectTemp <var>URL-path</var> <var>URL</var></code></td></tr>
404<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
405<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
406<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
407<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_alias</td></tr>
408</table>
409    <p>This directive makes the client know that the Redirect is
410    only temporary (status 302). Exactly equivalent to
411    <code>Redirect temp</code>.</p>
412
413</div>
414<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
415<div class="directive-section"><h2><a name="ScriptAlias" id="ScriptAlias">ScriptAlias</a> <a name="scriptalias" id="scriptalias">Directive</a></h2>
416<table class="directive">
417<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Maps a URL to a filesystem location and designates the
418target as a CGI script</td></tr>
419<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>ScriptAlias <var>URL-path</var>
420<var>file-path</var>|<var>directory-path</var></code></td></tr>
421<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
422<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
423<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_alias</td></tr>
424</table>
425    <p>The <code class="directive">ScriptAlias</code> directive has the same
426    behavior as the <code class="directive"><a href="#alias">Alias</a></code>
427    directive, except that in addition it marks the target directory
428    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
429    (%-decoded) path beginning with <var>URL-path</var> will be mapped
430    to scripts beginning with the second argument, which is a full
431    pathname in the local filesystem.</p>
432
433    <div class="example"><h3>Example:</h3><p><code>
434      ScriptAlias /cgi-bin/ /web/cgi-bin/
435    </code></p></div>
436
437    <p>A request for <code>http://example.com/cgi-bin/foo</code> would cause the
438    server to run the script <code>/web/cgi-bin/foo</code>.  This configuration
439    is essentially equivalent to:</p>
440    <div class="example"><p><code>
441      Alias /cgi-bin/ /web/cgi-bin/<br />
442      &lt;Location /cgi-bin &gt;<br />
443      <span class="indent">
444      SetHandler cgi-script<br />
445      Options +ExecCGI<br />
446      </span>
447      &lt;/Location&gt;
448    </code></p></div>
449
450    <div class="warning">It is safer to avoid placing CGI scripts under the
451    <code class="directive"><a href="/mod/core.html#documentroot">DocumentRoot</a></code> in order to
452    avoid accidentally revealing their source code if the
453    configuration is ever changed.  The
454    <code class="directive">ScriptAlias</code> makes this easy by mapping a
455    URL and designating CGI scripts at the same time.  If you do
456    choose to place your CGI scripts in a directory already
457    accessible from the web, do not use
458    <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:
459    <div class="example"><p><code>
460      &lt;Directory /usr/local/apache2/htdocs/cgi-bin &gt;<br />
461      <span class="indent">
462      SetHandler cgi-script<br />
463      Options ExecCGI<br />
464      </span>
465      &lt;/Directory&gt;
466    </code></p></div>
467    This is necessary since multiple <var>URL-paths</var> can map
468    to the same filesystem location, potentially bypassing the
469    <code class="directive">ScriptAlias</code> and revealing the source code
470    of the CGI scripts if they are not restricted by a
471    <code class="directive"><a href="/mod/core.html#directory">Directory</a></code> section.</div>
472
473
474<h3>See also</h3>
475<ul>
476<li><a href="/howto/cgi.html">CGI Tutorial</a></li>
477</ul>
478</div>
479<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
480<div class="directive-section"><h2><a name="ScriptAliasMatch" id="ScriptAliasMatch">ScriptAliasMatch</a> <a name="scriptaliasmatch" id="scriptaliasmatch">Directive</a></h2>
481<table class="directive">
482<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Maps a URL to a filesystem location using a regular expression
483and designates the target as a CGI script</td></tr>
484<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>ScriptAliasMatch <var>regex</var>
485<var>file-path</var>|<var>directory-path</var></code></td></tr>
486<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
487<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
488<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_alias</td></tr>
489</table>
490    <p>This directive is equivalent to <code class="directive"><a href="#scriptalias">ScriptAlias</a></code>, but makes use of
491    <a class="glossarylink" href="/glossary.html#regex" title="see glossary">regular expressions</a>,
492    instead of simple prefix matching. The
493    supplied regular expression is matched against the URL-path,
494    and if it matches, the server will substitute any parenthesized
495    matches into the given string and use it as a filename. For
496    example, to activate the standard <code>/cgi-bin</code>, one
497    might use:</p>
498
499    <div class="example"><p><code>
500      ScriptAliasMatch ^/cgi-bin(.*) /usr/local/apache/cgi-bin$1
501    </code></p></div>
502
503    <p>As for AliasMatch, the full range of <a class="glossarylink" href="/glossary.html#rexex" title="see glossary">regular
504    expression</a> power is available.
505    For example, it is possible to construct an alias with case-insensitive
506    matching of the URL-path:</p>
507
508    <div class="example"><p><code>
509      ScriptAliasMatch (?i)^/cgi-bin(.*) /usr/local/apache/cgi-bin$1
510    </code></p></div>
511
512    <p>The considerations related to the difference between
513    <code class="directive"><a href="#alias">Alias</a></code> and
514    <code class="directive"><a href="#aliasmatch">AliasMatch</a></code>
515    also apply to the difference between
516    <code class="directive"><a href="#scriptalias">ScriptAlias</a></code> and
517    <code class="directive"><a href="#scriptaliasmatch">ScriptAliasMatch</a></code>.
518    See <code class="directive"><a href="#aliasmatch">AliasMatch</a></code> for
519    details.</p>
520
521
522</div>
523</div>
524<div class="bottomlang">
525<p><span>Available Languages: </span><a href="/en/mod/mod_alias.html" title="English">&nbsp;en&nbsp;</a> |
526<a href="/ja/mod/mod_alias.html" hreflang="ja" rel="alternate" title="Japanese">&nbsp;ja&nbsp;</a> |
527<a href="/ko/mod/mod_alias.html" hreflang="ko" rel="alternate" title="Korean">&nbsp;ko&nbsp;</a> |
528<a href="/tr/mod/mod_alias.html" hreflang="tr" rel="alternate" title="T�rk�e">&nbsp;tr&nbsp;</a></p>
529</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>
530<script type="text/javascript"><!--//--><![CDATA[//><!--
531var comments_shortname = 'httpd';
532var comments_identifier = 'http://httpd.apache.org/docs/2.2/mod/mod_alias.html';
533(function(w, d) {
534    if (w.location.hostname.toLowerCase() == "httpd.apache.org") {
535        d.write('<div id="comments_thread"><\/div>');
536        var s = d.createElement('script');
537        s.type = 'text/javascript';
538        s.async = true;
539        s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
540        (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
541    }
542    else { 
543        d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>');
544    }
545})(window, document);
546//--><!]]></script></div><div id="footer">
547<p class="apache">Copyright 2013 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>
548<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[//><!--
549if (typeof(prettyPrint) !== 'undefined') {
550    prettyPrint();
551}
552//--><!]]></script>
553</body></html>