]> granicus.if.org Git - apache/blob - docs/manual/mod/mod_alias.html
PR: 4976
[apache] / docs / manual / mod / mod_alias.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
2 <HTML>
3 <HEAD>
4 <TITLE>Apache module mod_alias</TITLE>
5 </HEAD>
6
7 <!-- Background white, links blue (unvisited), navy (visited), red (active) -->
8 <BODY
9  BGCOLOR="#FFFFFF"
10  TEXT="#000000"
11  LINK="#0000FF"
12  VLINK="#000080"
13  ALINK="#FF0000"
14 >
15 <!--#include virtual="header.html" -->
16
17 <H1 ALIGN="CENTER">Module mod_alias</H1>
18 <P>
19 This module is contained in the <CODE>mod_alias.c</CODE> file, and
20 is compiled in by default. It provides for mapping different parts of the
21 host filesystem in the the document tree, and for URL redirection.
22 </P>
23
24 <H2>Directives</H2>
25 <UL>
26 <LI><A HREF="#alias">Alias</A>
27 <LI><A HREF="#aliasmatch">AliasMatch</A>
28 <LI><A HREF="#redirect">Redirect</A>
29 <LI><A HREF="#redirectmatch">RedirectMatch</A>
30 <LI><A HREF="#redirecttemp">RedirectTemp</A>
31 <LI><A HREF="#redirectperm">RedirectPermanent</A>
32 <LI><A HREF="#scriptalias">ScriptAlias</A>
33 <LI><A HREF="#scriptaliasmatch">ScriptAliasMatch</A>
34 </UL>
35 <HR>
36
37
38 <H2><A NAME="alias">Alias directive</A></H2>
39 <P>
40 <!--%plaintext &lt;?INDEX {\tt Alias} directive&gt; -->
41 <A
42  HREF="directive-dict.html#Syntax"
43  REL="Help"
44 ><STRONG>Syntax:</STRONG></A> Alias <EM>url-path directory-filename</EM><BR>
45 <A
46  HREF="directive-dict.html#Context"
47  REL="Help"
48 ><STRONG>Context:</STRONG></A> server config, virtual host<BR>
49 <A
50  HREF="directive-dict.html#Status"
51  REL="Help"
52 ><STRONG>Status:</STRONG></A> Base<BR>
53 <A
54  HREF="directive-dict.html#Module"
55  REL="Help"
56 ><STRONG>Module:</STRONG></A> mod_alias
57 </P>
58 <P>
59 The Alias directive allows documents to be stored in the local filesystem
60 other than under the <A HREF="core.html#documentroot">DocumentRoot</A>.
61 URLs with a (%-decoded) path beginning with <EM>url-path</EM> will be
62 mapped to local files beginning with <EM>directory-filename</EM>.
63 <P>
64 Example:
65 </P>
66 <BLOCKQUOTE><CODE>Alias /image /ftp/pub/image</CODE></BLOCKQUOTE>
67 <P>
68 A request for http://myserver/image/foo.gif would cause the server to
69 return the file /ftp/pub/image/foo.gif.
70 </P>
71 <P>
72 Note that if you include a trailing / on the <EM>url-path</EM> then the
73 server will require a trailing / in order to expand the alias.  That is,
74 if you use <CODE>Alias /icons/ /usr/local/apache/icons/</CODE> then
75 the url <CODE>/icons</CODE> will not be aliased.
76 </P>
77 <P>
78 Note that you may need to specify additional
79 <A HREF="core.html#directory"><CODE>&lt;Directory&gt;</CODE></A> sections
80 which cover the <EM>destination</EM> of aliases.  Aliasing occurs
81 before <CODE>&lt;Directory&gt;</CODE> sections are checked, so only
82 the destination of aliases are affected.  (Note however
83 <A HREF="core.html#location"><CODE>&lt;Location&gt;</CODE></A>
84 sections are run through once before aliases are performed, so they
85 will apply.)
86 <P>
87 See also <A HREF="#scriptalias">ScriptAlias</A>.
88 </P>
89 <HR>
90
91 <H2><A NAME="aliasmatch">AliasMatch</A></H2>
92 <P>
93 <A
94  HREF="directive-dict.html#Syntax"
95  REL="Help"
96 ><STRONG>Syntax:</STRONG></A> AliasMatch <EM>regex directory-filename</EM><BR>
97 <A
98  HREF="directive-dict.html#Context"
99  REL="Help"
100 ><STRONG>Context:</STRONG></A> server config, virtual host<BR>
101 <A
102  HREF="directive-dict.html#Status"
103  REL="Help"
104 ><STRONG>Status:</STRONG></A> Base<BR>
105 <A
106  HREF="directive-dict.html#Module"
107  REL="Help"
108 ><STRONG>Module:</STRONG></A> mod_alias<BR>
109 <A
110  HREF="directive-dict.html#Compatibility"
111  REL="Help"
112 ><STRONG>Compatibility:</STRONG></A> Available in Apache 1.3 and later
113 </P>
114
115 <P>This directive is equivalent to <A HREF="#alias">Alias</A>, but
116 makes use of standard regular expressions, instead of simple prefix
117 matching. The supplied regular expression is matched against the URL,
118 and if it matches, the server will substitute any parenthesized
119 matches into the given string and use it as a filename. For example,
120 to activate the <CODE>/icons</CODE> directory, one might use:
121 <PRE>
122     AliasMatch ^/icons(.*) /usr/local/apache/icons$1
123 </PRE>
124 </P>
125
126 <HR>
127
128 <H2><A NAME="redirect">Redirect directive</A></H2>
129 <P>
130 <!--%plaintext &lt;?INDEX {\tt Redirect} directive&gt; -->
131 <A
132  HREF="directive-dict.html#Syntax"
133  REL="Help"
134 ><STRONG>Syntax:</STRONG></A> Redirect [ <EM>status</EM> ]
135  <EM>url-path url</EM><BR>
136 <A
137  HREF="directive-dict.html#Context"
138  REL="Help"
139 ><STRONG>Context:</STRONG></A> server config, virtual host, directory,
140  .htaccess<BR>
141 <A
142  HREF="directive-dict.html#Override"
143  REL="Help"
144 ><STRONG>Override:</STRONG></A> FileInfo<BR>
145 <A
146  HREF="directive-dict.html#Status"
147  REL="Help"
148 ><STRONG>Status:</STRONG></A> Base<BR>
149 <A
150  HREF="directive-dict.html#Module"
151  REL="Help"
152 ><STRONG>Module:</STRONG></A> mod_alias<BR>
153 <A
154  HREF="directive-dict.html#Compatibility"
155  REL="Help"
156 ><STRONG>Compatibility:</STRONG></A> The directory and .htaccess context's
157 are only available in versions 1.1 and later. The <EM>status</EM>
158 argument is only available in Apache 1.2 or later.
159 </P>
160 <P>
161 The Redirect directive maps an old URL into a new one. The new URL is returned
162 to the client which attempts to fetch it again with the new address.
163 <EM>Url-path</EM> a (%-decoded) path; any requests for documents beginning with
164 this path will be returned a redirect error to a new (%-encoded) url
165 beginning with <EM>url</EM>.
166 </P>
167 <P>
168 Example:
169 </P>
170 <BLOCKQUOTE><CODE>Redirect /service
171 http://foo2.bar.com/service</CODE></BLOCKQUOTE>
172 <P>
173 If the client requests http://myserver/service/foo.txt, it will be told to
174 access http://foo2.bar.com/service/foo.txt instead.
175 </P>
176 <P>
177 <STRONG>Note:</STRONG> Redirect directives take precedence over Alias
178 and ScriptAlias
179 directives, irrespective of their ordering in the configuration file.  Also,
180 <EM>Url-path</EM> must be an absolute path, not a relative path, even
181 when used with .htaccess files or inside of &lt;Directory&gt; sections.
182 </P>
183 <P>
184 If no <EM>status</EM> argument is given, the redirect will be
185 &quot;temporary&quot; (HTTP status 302). This indicates to the client that the
186 resource has moved temporarily. The <EM>status</EM>
187 argument can be used to return other HTTP status codes:
188 <P>
189 <DL>
190 <DT>permanent
191 <DD>Returns a permanent redirect status (301) indicating that
192 the resource has moved permanently.
193 <DT>temp
194 <DD>Returns a temporary redirect status (302). This is the
195 default.
196 <DT>seeother
197 <DD>Returns a "See Other" status (303) indicating that
198 the resource has been replaced.
199 <DT>gone
200 <DD>Returns a "Gone" status (410) indicating that the resource
201 has been permanently removed. When this status is used the <EM>url</EM>
202 argument should be omitted.
203 </DL>
204 <P>
205 Other status codes can be returned by giving the numeric status code
206 as the value of <EM>status</EM>. If the status is between 300 and 399,
207 the <EM>url</EM> argument must be present, otherwise it must be
208 omitted. Note that the status must be known to the Apache code (see
209 the function <CODE>send_error_response</CODE> in http_protocol.c).
210 </P>
211 <HR>
212
213 <H2><A NAME="redirectmatch">RedirectMatch</A></H2>
214 <P>
215 <A
216  HREF="directive-dict.html#Syntax"
217  REL="Help"
218 ><STRONG>Syntax:</STRONG></A>
219     RedirectMatch [<EM>status</EM>] <EM>regex url</EM>
220 <BR>
221 <A
222  HREF="directive-dict.html#Context"
223  REL="Help"
224 ><STRONG>Context:</STRONG></A> server config, virtual host, directory,
225  .htaccess<BR>
226 <A
227  HREF="directive-dict.html#Override"
228  REL="Help"
229 ><STRONG>Override:</STRONG></A> FileInfo<BR>
230 <A
231  HREF="directive-dict.html#Status"
232  REL="Help"
233 ><STRONG>Status:</STRONG></A> Base<BR>
234 <A
235  HREF="directive-dict.html#Module"
236  REL="Help"
237 ><STRONG>Module:</STRONG></A> mod_alias<BR>
238 <A
239  HREF="directive-dict.html#Compatibility"
240  REL="Help"
241 ><STRONG>Compatibility:</STRONG></A> Available in Apache 1.3 and later
242 </P>
243
244 <P>This directive is equivalent to <A HREF="#alias">Redirect</A>, but
245 makes use of standard regular expressions, instead of simple prefix
246 matching. The supplied regular expression is matched against the URL,
247 and if it matches, the server will substitute any parenthesized
248 matches into the given string and use it as a filename. For example,
249 to redirect all GIF files to like-named JPEG files on another server,
250 one might use:
251 <PRE>
252     RedirectMatch (.*)\.gif$ http://www.anotherserver.com$1.jpg
253 </PRE>
254 </P>
255
256 <HR>
257
258 <H2><A NAME="redirecttemp">RedirectTemp directive</A></H2>
259 <P>
260 <!--%plaintext &lt;?INDEX {\tt Redirect} directive&gt; -->
261 <A
262  HREF="directive-dict.html#Syntax"
263  REL="Help"
264 ><STRONG>Syntax:</STRONG></A> RedirectTemp <EM>url-path url</EM><BR>
265 <A
266  HREF="directive-dict.html#Context"
267  REL="Help"
268 ><STRONG>Context:</STRONG></A> server config, virtual host, directory,
269  .htaccess<BR>
270 <A
271  HREF="directive-dict.html#Override"
272  REL="Help"
273 ><STRONG>Override:</STRONG></A> FileInfo<BR>
274 <A
275  HREF="directive-dict.html#Status"
276  REL="Help"
277 ><STRONG>Status:</STRONG></A> Base<BR>
278 <A
279  HREF="directive-dict.html#Module"
280  REL="Help"
281 ><STRONG>Module:</STRONG></A> mod_alias<BR>
282 <A
283  HREF="directive-dict.html#Compatibility"
284  REL="Help"
285 ><STRONG>Compatibility:</STRONG></A> This directive is only available in Apache 1.2 and later
286 </P>
287 <P>
288 This directive makes the client know that the Redirect is only
289 temporary (status 302). Exactly equivalent to <CODE>Redirect
290 temp</CODE>.
291 </P>
292 <HR>
293
294 <H2><A NAME="redirectperm">RedirectPermanent directive</A></H2>
295 <P>
296 <!--%plaintext &lt;?INDEX {\tt Redirect} directive&gt; -->
297 <A
298  HREF="directive-dict.html#Syntax"
299  REL="Help"
300 ><STRONG>Syntax:</STRONG></A> RedirectPermanent <EM>url-path url</EM><BR>
301 <A
302  HREF="directive-dict.html#Context"
303  REL="Help"
304 ><STRONG>Context:</STRONG></A> server config, virtual host, directory,
305  .htaccess<BR>
306 <A
307  HREF="directive-dict.html#Override"
308  REL="Help"
309 ><STRONG>Override:</STRONG></A> FileInfo<BR>
310 <A
311  HREF="directive-dict.html#Status"
312  REL="Help"
313 ><STRONG>Status:</STRONG></A> Base<BR>
314 <A
315  HREF="directive-dict.html#Module"
316  REL="Help"
317 ><STRONG>Module:</STRONG></A> mod_alias<BR>
318 <A
319  HREF="directive-dict.html#Compatibility"
320  REL="Help"
321 ><STRONG>Compatibility:</STRONG></A> This directive is only available in Apache 1.2 and later
322 </P>
323 <P>
324 This directive makes the client know that the Redirect is permanent
325 (status 301). Exactly equivalent to <CODE>Redirect permanent</CODE>.
326 </P>
327 <HR>
328
329 <H2><A NAME="scriptalias">ScriptAlias directive</A></H2>
330 <P>
331 <!--%plaintext &lt;?INDEX {\tt ScriptAlias} directive&gt; -->
332 <A
333  HREF="directive-dict.html#Syntax"
334  REL="Help"
335 ><STRONG>Syntax:</STRONG></A> ScriptAlias <EM>url-path directory-filename</EM>
336 <BR>
337 <A
338  HREF="directive-dict.html#Context"
339  REL="Help"
340 ><STRONG>Context:</STRONG></A> server config, virtual host<BR>
341 <A
342  HREF="directive-dict.html#Status"
343  REL="Help"
344 ><STRONG>Status:</STRONG></A> Base<BR>
345 <A
346  HREF="directive-dict.html#Module"
347  REL="Help"
348 ><STRONG>Module:</STRONG></A> mod_alias
349 </P>
350 <P>
351 The ScriptAlias directive has the same behavior as the
352 <A HREF="#alias">Alias</A> directive, except that in addition it
353 marks the target directory as containing CGI scripts.
354 URLs with a (%-decoded) path beginning with <EM>url-path</EM> will be
355 mapped to scripts beginning with <EM>directory-filename</EM>.
356 <P>
357 Example:
358 </P>
359 <BLOCKQUOTE><CODE>ScriptAlias /cgi-bin/ /web/cgi-bin/</CODE></BLOCKQUOTE>
360 <P>
361 A request for http://myserver/cgi-bin/foo would cause the server to
362 run the script /web/cgi-bin/foo.
363 </P>
364
365 <HR>
366
367 <H2><A NAME="scriptaliasmatch">ScriptAliasMatch</A></H2>
368 <P>
369 <A
370  HREF="directive-dict.html#Syntax"
371  REL="Help"
372 ><STRONG>Syntax:</STRONG></A> ScriptAliasMatch
373  <EM>regex directory-filename</EM><BR>
374 <A
375  HREF="directive-dict.html#Context"
376  REL="Help"
377 ><STRONG>Context:</STRONG></A> server config, virtual host<BR>
378 <A
379  HREF="directive-dict.html#Status"
380  REL="Help"
381 ><STRONG>Status:</STRONG></A> Base<BR>
382 <A
383  HREF="directive-dict.html#Module"
384  REL="Help"
385 ><STRONG>Module:</STRONG></A> mod_alias<BR>
386 <A
387  HREF="directive-dict.html#Compatibility"
388  REL="Help"
389 ><STRONG>Compatibility:</STRONG></A> Available in Apache 1.3 and later
390 </P>
391
392 <P>This directive is equivalent to <A HREF="#scriptalias">ScriptAlias</A>, but
393 makes use of standard regular expressions, instead of simple prefix
394 matching. The supplied regular expression is matched against the URL,
395 and if it matches, the server will substitute any parenthesized
396 matches into the given string and use it as a filename. For example,
397 to activate the standard <CODE>/cgi-bin</CODE>, one might use:
398 <PRE>
399     ScriptAliasMatch ^/cgi-bin(.*) /usr/local/apache/cgi-bin$1
400 </PRE>
401 </P>
402
403 <!--#include virtual="footer.html" -->
404 </BODY>
405 </HTML>