Apache Module mod_alias
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
The directives contained in this module allow for manipulation and control of URLs as requests arrive at the server. The
directives are used to map between URLs and filesystem paths. This allows for content which is not directly under the ScriptAlias
served as part of the web document tree. The DocumentRoot
directive has the additional effect of marking the target directory as containing only CGI scripts.ScriptAlias
directives are used to instruct clients to make a new request with a different URL. They are often used when a resource has moved to a new location.Redirect
is designed to handle simple URL manipulation tasks. For more complicated tasks such as manipulating the query string, use the tools provided by mod_alias
First, all Redirects are processed before Aliases are processed, and therefore a request that matches a
will never have Aliases applied. Second, the Aliases and Redirects are processed in the order they appear in the configuration files, with the first match taking precedence.RedirectMatch
For this reason, when two or more of these directives apply to the same sub-path, you must list the most specific path first in order for all the directives to have an effect. For example, the following configuration will work as expected:
Alias /foo/bar /baz Alias /foo /gaq
But if the above two directives were reversed in order, the /foo
, so the latter directive would be ignored.Alias
Alias /image /ftp/pub/image
would cause the server to return the file /ftp/pub/image/foo.gif
. Only complete path segments are matched, so the above alias would not match a request for http://example.com/imagefoo.gif
. For more complex matching using regular expressions, see the
Note that if you include a trailing / on the 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/
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 file-path.
Note that you may need to specify additional
sections which
cover the
sections
are checked, so only the destination of aliases are affected.
(Note however
sections are run through once before aliases are performed, so
they will apply.)
, you may need to explicitly permit access to the target directory.DocumentRoot
Any number slashes in the URL-path parameter matches any number of slashes in the requested URL-path.
, but makes use of Aliasregular expressions, instead of simple prefix matching. The supplied regular expression is matched against the URL-path, and if it matches, the server will substitute any parenthesized matches into the given string and use it as a filename. For example, to activate the /icons
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:
One subtle difference between
will automatically copy any additional part of the URI, past the part that matched, onto the end of the file path on the right side, while Alias
will not. This means that in almost all cases, you will want the regular expression to match the entire request URI from beginning to end, and to use substitution on the right side.AliasMatch
In other words, just changing
For example, suppose you want to replace this with AliasMatch:
This is NOT equivalent - don't do this! This will send all requests that have /image/ anywhere in them to /ftp/pub/image/:
Of course, there's no point in using
lets you do more complicated things. For example, you could serve different kinds of files from different directories:AliasMatch
AliasMatch ^/image/(.*)\.jpg$ /files/jpg.images/$1.jpg
Multiple leading slashes in the requested URL are discarded by the server before directives from this module compares against the requested URL-path.
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 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.
Then any request beginning with URL-Path will return a redirect request to the client at the location of the target URL. Additional path information beyond the matched URL-Path will be appended to the target URL.
parameters, such as http://example.com/service/foo.pl?q=23&a=42
Redirect directives take precedence over Alias and ScriptAlias directives, irrespective of their ordering in the configuration file.
If no status argument is given, the redirect will be "temporary" (HTTP status 302). This indicates to the client that the resource has moved temporarily. The status argument can be used to return other HTTP status codes:
Other status codes can be returned by giving the numeric status code as the value of status. If the status is between 300 and 399, the URL argument must be present. If the status is not between 300 and 399, the URL argument must be omitted. The status must be a valid HTTP status code, known to the Apache HTTP Server (see the function senderrorresponse
, but makes use of Redirectregular expressions, instead of simple prefix matching. The supplied regular expression is matched against the URL-path, and if it matches, the server will substitute any parenthesized matches into the given string and use it as a filename. For example, to redirect all GIF files to like-named JPEG files on another server, one might use:
The considerations related to the difference between
's cgi-script handler. URLs with a case-sensitive (%-decoded) path beginning with mod_cgiURL-path will be mapped to scripts beginning with the second argument, which is a full pathname in the local filesystem.
Alias /cgi-bin/ /web/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 content, or some other bespoke action.
in order to avoid accidentally revealing their source code if the configuration is ever changed. The ScriptAlias
makes this easy by mapping a URL and designating CGI scripts at the same time. If you do choose to place your CGI scripts in a directory already accessible from the web, do not use ScriptAlias
as in:
Modules | Directives | FAQ | Glossary | Sitemap
Apache HTTP Server Version 2.4
Apache Module mod_alias
Available Languages: en | fr | ja | ko | tr
Order of Processing
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
Alias Directive
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 to local files beginning with directory-path. The URL-path is case-sensitive, even on case-insensitive file systems.
AliasMatch Directive
This directive is equivalent to Alias, but makes use of regular expressions, instead of simple prefix matching. The supplied regular expression is matched against the URL-path, and if it matches, the server will substitute any parenthesized matches into the given string and use it as a filename. For
Redirect Directive
The Redirect directive maps an old URL into a new one by asking the client to refetch the resource at the new location.
RedirectMatch Directive
This directive is equivalent to Redirect, but makes use of regular expressions, instead of simple prefix matching. The supplied regular expression is matched against the URL-path, and if it matches, the server will substitute any parenthesized matches into the given string and use it as a filename.
RedirectPermanent Directive
This directive makes the client know that the Redirect is permanent (status 301). Exactly equivalent to Redirect permanent.
RedirectTemp Directive
This directive makes the client know that the Redirect is only temporary (status 302). Exactly equivalent to Redirect temp.
ScriptAlias Directive
The ScriptAlias directive has the same behavior as the Alias directive, except that in addition it marks the target directory as containing CGI scripts that will be processed by mod_cgi's cgi-script handler. URLs with a case-sensitive (%-decoded) path beginning with URL-path will be mapped to script
ScriptAliasMatch Directive
This directive is equivalent to ScriptAlias, but makes use of regular expressions, instead of simple prefix matching. The supplied regular expression is matched against the URL-path, and if it matches, the server will substitute any parenthesized matches into the given string and use it as a filenam