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