X-Git-Url: https://granicus.if.org/sourcecode?a=blobdiff_plain;f=docs%2Fmanual%2Fmod%2Fmod_alias.html.en;h=295c1f2d6d405a8fe80abe45091374c13319884b;hb=430aadce59b536d533be35d333eebfe579a94d16;hp=64f52189334c4a83feb523252312663314caf08c;hpb=1b2cc09c0463b5ee9013c36673e75b72a26bf9e6;p=apache diff --git a/docs/manual/mod/mod_alias.html.en b/docs/manual/mod/mod_alias.html.en index 64f5218933..295c1f2d6d 100644 --- a/docs/manual/mod/mod_alias.html.en +++ b/docs/manual/mod/mod_alias.html.en @@ -5,19 +5,22 @@ This file is generated from xml source: DO NOT EDIT XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX --> -mod_alias - Apache HTTP Server +mod_alias - Apache HTTP Server Version 2.5 - + + +
<-
-Apache > HTTP Server > Documentation > Version 2.3 > Modules
+Apache > HTTP Server > Documentation > Version 2.5 > Modules

Apache Module mod_alias

@@ -48,13 +51,25 @@ a different URL. They are often used when a resource has moved to a new location.

+

When the Alias, + ScriptAlias and + Redirect directives are used + within a <Location> + or <LocationMatch> + section, expression syntax can be used + to manipulate the destination path or URL. +

+

mod_alias is designed to handle simple URL manipulation tasks. For more complicated tasks such as manipulating the query string, use the tools provided by mod_rewrite.

-

Directives

+

Topics

+

Directives

-

Topics

-

See also

+

See also

+
top

Order of Processing

-

Aliases and Redirects occuring in different contexts are processed +

Aliases and Redirects occurring in different contexts are processed like other directives according to standard merging rules. But when multiple Aliases or Redirects occur in the same context (for example, in the same <VirtualHost> @@ -94,24 +106,33 @@ all the directives to have an effect. For example, the following configuration will work as expected:

-

- Alias /foo/bar /baz
- Alias /foo /gaq -

+
Alias "/foo/bar" "/baz"
+Alias "/foo"     "/gaq"
+

But if the above two directives were reversed in order, the /foo Alias would always match before the /foo/bar Alias, so the latter directive would be ignored.

+

When the Alias, + ScriptAlias and + Redirect directives are used + within a <Location> + or <LocationMatch> + section, these directives will take precedence over any globally + defined Alias, + ScriptAlias and + Redirect directives.

+
top

Alias Directive

- - +
Description:Maps URLs to filesystem locations
Syntax:Alias URL-path +
Syntax:Alias [URL-path] file-path|directory-path
Context:server config, virtual host
Context:server config, virtual host, directory
Status:Base
Module:mod_alias
@@ -119,14 +140,13 @@

The Alias directive allows documents to be stored in the local filesystem other than under the DocumentRoot. URLs with a - (%-decoded) path beginning with url-path will be mapped + (%-decoded) path beginning with URL-path will be mapped to local files beginning with directory-path. The - url-path is case-sensitive, even on case-insensitive + URL-path is case-sensitive, even on case-insensitive file systems.

-

Example:

- Alias /image /ftp/pub/image -

+
Alias "/image" "/ftp/pub/image"
+

A request for http://example.com/image/foo.gif would cause the server to return the file /ftp/pub/image/foo.gif. Only @@ -135,14 +155,15 @@ matching using regular expressions, see the AliasMatch directive.

Note that if you include a trailing / on the - url-path then the server will require a trailing / in + URL-path then the server will require a trailing / in order to expand the alias. That is, if you use

-
Alias /icons/ /usr/local/apache/icons/
+
Alias "/icons/" "/usr/local/apache/icons/"
+

then the url /icons will not be aliased, as it lacks that trailing /. Likewise, if you omit the slash on the - url-path then you must also omit it from the + URL-path then you must also omit it from the file-path.

Note that you may need to specify additional <Directory> sections which @@ -157,14 +178,28 @@ directory outside of your DocumentRoot, you may need to explicitly permit access to the target directory.

-

Example:

- Alias /image /ftp/pub/image
- <Directory /ftp/pub/image>
- - Require all granted
-
- </Directory> -

+
Alias "/image" "/ftp/pub/image"
+<Directory "/ftp/pub/image">
+    Require all granted
+</Directory>
+ + +

Any number slashes in the URL-path parameter + matches any number of slashes in the requested URL-path.

+ +

If the Alias directive is used within a + <Location> + or <LocationMatch> + section the URL-path is omitted, and the file-path is interpreted + using expression syntax.

+ +
<Location "/image">
+    Alias "/ftp/pub/image"
+</Location>
+<LocationMatch "/error/(?<NUMBER>[0-9]+)">
+    Alias "/usr/local/apache/errors/%{env:MATCH_NUMBER}.html"
+</LocationMatch>
+
@@ -188,18 +223,16 @@ expressions example, to activate the /icons directory, one might use:

-

- AliasMatch ^/icons(.*) /usr/local/apache/icons$1 -

+
AliasMatch "^/icons(/|$)(.*)" "/usr/local/apache/icons$1$2"
+

The full range of regular expression power is available. For example, it is possible to construct an alias with case-insensitive - matching of the url-path:

+ matching of the URL-path:

+ +
AliasMatch "(?i)^/image(.*)" "/ftp/pub/image$1"
-

- AliasMatch (?i)^/image(.*) /ftp/pub/image$1 -

One subtle difference between Alias @@ -212,7 +245,7 @@ expressions regular expression to match the entire request URI from beginning to end, and to use substitution on the right side.

-

In other words, just changing +

In other words, just changing Alias to AliasMatch will not have the same effect. At a minimum, you need to @@ -222,22 +255,19 @@ expressions

For example, suppose you want to replace this with AliasMatch:

-

- Alias /image/ /ftp/pub/image/ -

+
Alias "/image/" "/ftp/pub/image/"
+

This is NOT equivalent - don't do this! This will send all requests that have /image/ anywhere in them to /ftp/pub/image/:

-

- AliasMatch /image/ /ftp/pub/image/ -

+
AliasMatch "/image/" "/ftp/pub/image/"
+

This is what you need to get the same effect:

-

- AliasMatch ^/image/(.*)$ /ftp/pub/image/$1 -

+
AliasMatch "^/image/(.*)$" "/ftp/pub/image/$1"
+

Of course, there's no point in using AliasMatch @@ -246,10 +276,14 @@ expressions you do more complicated things. For example, you could serve different kinds of files from different directories:

-

- AliasMatch ^/image/(.*)\.jpg$ /files/jpg.images/$1.jpg
- AliasMatch ^/image/(.*)\.gif$ /files/gif.images/$1.gif -

+
AliasMatch "^/image/(.*)\.jpg$" "/files/jpg.images/$1.jpg"
+AliasMatch "^/image/(.*)\.gif$" "/files/gif.images/$1.gif"
+ + +

Multiple leading slashes in the requested URL are discarded + by the server before directives from this module compares + against the requested URL-path. +

@@ -258,7 +292,7 @@ expressions - @@ -270,8 +304,8 @@ a different URL

The old URL-path is a case-sensitive (%-decoded) path beginning with a slash. A relative path is not allowed.

- -

The new URL may be either an absolute URL beginning + +

The new URL may be either an absolute URL beginning with a scheme and hostname, or a URL-path beginning with a slash. In this latter case the scheme and hostname of the current server will be added.

@@ -281,32 +315,34 @@ a different URLURL. Additional path information beyond the matched URL-Path will be appended to the target URL.

-

Example:

- # Redirect to a URL on a different host
- Redirect /service http://foo2.example.com/service
-
- # Redirect to a URL on the same host
- Redirect /one /two -

+
# Redirect to a URL on a different host
+Redirect "/service" "http://foo2.example.com/service"
+
+# Redirect to a URL on the same host
+Redirect "/one" "/two"
+

If the client requests http://example.com/service/foo.txt, it will be told to access http://foo2.example.com/service/foo.txt instead. This includes requests with GET parameters, such as http://example.com/service/foo.pl?q=23&a=42, - it will be redirected to + it will be redirected to http://foo2.example.com/service/foo.pl?q=23&a=42. Note that POSTs will be discarded.
Only complete path segments are matched, so the above example would not match a request for - http://example.com/servicefoo.txt. For more complex matching - using regular expressions, see the RedirectMatch directive.

+ http://example.com/servicefoo.txt. For more complex matching + using the expression syntax, omit the URL-path + argument as described below. Alternatively, for matching using regular + expressions, see the RedirectMatch directive.

Note

Redirect directives take precedence over Alias and ScriptAlias directives, irrespective of their ordering in the configuration - file.

+ file. Redirect directives inside a Location take precedence over + Redirect and Alias directives with an URL-path.

If no status argument is given, the redirect will be "temporary" (HTTP status 302). This indicates to the client @@ -344,10 +380,27 @@ a different URL HTTP status code, known to the Apache HTTP Server (see the function send_error_response in http_protocol.c).

-

Example:

- Redirect permanent /one http://example.com/two
- Redirect 303 /three http://example.com/other -

+
Redirect permanent "/one" "http://example.com/two"
+Redirect 303 "/three" "http://example.com/other"
+ + +

If the Redirect directive is used within a + <Location> + or <LocationMatch> + section with the URL-path omitted, then the URL parameter will be + interpreted using expression syntax.

+ +
<Location "/one">
+    Redirect permanent "http://example.com/two"
+</Location>
+<Location "/three"> + Redirect 303 "http://example.com/other" +</Location>
+<LocationMatch "/error/(?<NUMBER>[0-9]+)"> + Redirect permanent "http://example.com/errors/%{env:MATCH_NUMBER}.html" +</LocationMatch>
+
+ @@ -372,9 +425,8 @@ of the current URL example, to redirect all GIF files to like-named JPEG files on another server, one might use:

-

- RedirectMatch (.*)\.gif$ http://other.example.com$1.jpg -

+
RedirectMatch "(.*)\.gif$" "http://other.example.com$1.jpg"
+

The considerations related to the difference between Alias and @@ -425,9 +477,9 @@ a different URL

Description:Sends an external redirect asking the client to fetch a different URL
Syntax:Redirect [status] URL-path +
Syntax:Redirect [status] [URL-path] URL
Context:server config, virtual host, directory, .htaccess
Override:FileInfo
- - +
Description:Maps a URL to a filesystem location and designates the target as a CGI script
Syntax:ScriptAlias URL-path +
Syntax:ScriptAlias [URL-path] file-path|directory-path
Context:server config, virtual host
Context:server config, virtual host, directory
Status:Base
Module:mod_alias
@@ -439,33 +491,28 @@ target as a CGI script to scripts beginning with the second argument, which is a full pathname in the local filesystem.

-

Example:

- ScriptAlias /cgi-bin/ /web/cgi-bin/ -

+
ScriptAlias "/cgi-bin/" "/web/cgi-bin/"
+

A request for http://example.com/cgi-bin/foo would cause the server to run the script /web/cgi-bin/foo. This configuration is essentially equivalent to:

-

- Alias /cgi-bin/ /web/cgi-bin/
- <Location /cgi-bin >
- - SetHandler cgi-script
- Options +ExecCGI
-
- </Location> -

+
Alias "/cgi-bin/" "/web/cgi-bin/"
+<Location "/cgi-bin">
+    SetHandler cgi-script
+    Options +ExecCGI
+</Location>
+

ScriptAlias can also be used in conjunction with a script or handler you have. For example:

- -

- ScriptAlias /cgi-bin/ /web/cgi-handler.pl -

- + +
ScriptAlias "/cgi-bin/" "/web/cgi-handler.pl"
+ +

In this scenario all files requested in /cgi-bin/ will be - handled by the file you have configured, this allows you to use your own custom - handler. You may want to use this as a wrapper for CGI so that you can add + handled by the file you have configured, this allows you to use your own custom + handler. You may want to use this as a wrapper for CGI so that you can add content, or some other bespoke action.

It is safer to avoid placing CGI scripts under the @@ -477,20 +524,32 @@ target as a CGI script choose to place your CGI scripts in a directory already accessible from the web, do not use ScriptAlias. Instead, use <Directory>, SetHandler, and Options as in: -

- <Directory /usr/local/apache2/htdocs/cgi-bin >
- - SetHandler cgi-script
- Options ExecCGI
-
- </Directory> -

+
<Directory "/usr/local/apache2/htdocs/cgi-bin">
+    SetHandler cgi-script
+    Options ExecCGI
+</Directory>
+ This is necessary since multiple URL-paths can map to the same filesystem location, potentially bypassing the ScriptAlias and revealing the source code of the CGI scripts if they are not restricted by a Directory section.
+

If the ScriptAlias directive is used within + a <Location> + or <LocationMatch> + section with the URL-path omitted, then the URL parameter will be + interpreted using expression syntax.

+ +
<Location "/cgi-bin">
+    ScriptAlias "/web/cgi-bin/"
+</Location>
+<LocationMatch "/cgi-bin/errors/(?<NUMBER>[0-9]+)">
+    ScriptAlias "/web/cgi-bin/errors/%{env:MATCH_NUMBER}.cgi"
+</LocationMatch>
+
+ +

See also

+
top

Comments

Notice:
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 mailing lists.
+
\ No newline at end of file