Module mod_alias

Module mod_alias contains directives for the IBM® HTTP Server for i Web server.

Summary

The module mod_alias provides mapping for different parts of the host file system in the document tree and also for URL redirection.

Directives

Alias

Module: mod_alias
Syntax: Alias [URL-path] file-path | directory-path
Default: none
Context: server config, virtual host
Override: none
Origin: Apache
Example: Alias /image /QIBM/UserData/pub/image
Example: Alias /httpfile/ /QSYS.LIB/AS400LIB.LIB/HTML.FILE/

This directive allows documents to be stored in the local filesystem other than under the DocumentRoot. URLs with a (%-decoded) path beginning with the value of the URL-path parameter will be mapped to local files beginning with the value of directory-filename. Alias also allows you to hide the file system path from users, enhancing both security of your server and the ability to change the filesystem structure or paths without impacting the end users.

Parameter One: url-path
  • The url-path paramter is any valid URL path. If you include a trailing '/' in the URL path, then the server will require a trailing '/' in order to expand the alias. That is, if you use 'Alias /icons/ /www/images/i/icons/' then the URL '/icon' will not be aliased.
Parameter Two: file-path | directory-path
  • The file-path | directory-path parameter is any valid directory/filename combination on the system.
Note: You may need to specify additional <Directory> containers that cover the destination of aliases. Aliasing occurs before <Directory> containers are checked, so only the destination of aliases are affected. <Location> containers are run through once before aliases are performed, so they will apply.

In particular, if you are creating an Alias to a directory outside of your DocumentRoot, you may need to explicitly permit access to the target 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 with the URL-path is omitted, then the file-path will be interpreted using expression syntax.

<Location "/image">
    Alias "/ftp/pub/image"
</Location>
<LocationMatch "/error/(?<NUMBER>[0-9]+)">
    Alias "/www/webserver/htdocs/errors/%{env:MATCH_NUMBER}.html"
</LocationMatch>

See ScriptAlias for more information.

AliasMatch

Module: mod_alias
Syntax: AliasMatch regex directory-filename
Default: none
Context: server config, virtual host
Override: none
Origin: Apache
Example: AliasMatch ^/icons(.*) /www/images/HTTP_Server/icons$1
Example: AliasMatch ^/lib/docs(.*) /QSYS.LIB/DOCLIB.LIB/HTMLDOC.FILE/$1.MBR

This directive is equivalent to Alias, but makes use of standard regular expressions, instead of simple prefix matching. The supplied regular expression is matched against the URL, and if it matches, the server will substitute any parenthesized matches into the given string and use it as a filename.

Parameter One: regex
  • The regex parameter is a regular expression that is matched against the URL. Subexpressions are grouped within parentheses. Then parenthetically enclosed regular expressions will be substituted in a subsequent $n statement.
Parameter Two: directory-filename
  • The directory-filename parameter is any valid directory/filename that is supported on the IBM i server. If there is a $ symbol (followed by a digit) that is not a substitution variable in the directory-filename parameter, or there is an & symbol in the directory-filename parameter that is part of the directory or filename, the symbol must be escaped (\).

If the directory-filename is /usr/local/apache/icons&gifs/ the & would need to be escaped as follows on the AliasMatch directive:

AliasMatch  ^/icons(.*) /usr/local/apache/icons\gifs/

One subtle difference between Alias and AliasMatch is that Alias 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 AliasMatch 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.

In other words, just changing Alias to AliasMatch will not have the same effect. At a minimum, you need to add ^ to the beginning of the regular expression and add (.*)$ to the end, and add $1 to the end of the replacement.

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

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/

This is what you need to get the same effect:

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

Of course, there's no point in using AliasMatch where Alias would work. AliasMatch lets 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

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

See Regular expression notation for more information regarding regular expressions.

MapMatch

Module: mod_alias
Syntax: MapMatch regex URI
Default: none
Context: server config, virtual host
Override: none
Origin: Apache
Example: MapMatch ^/icons(.*) /www/apache/icons\&gifs/

The MapMatch directive uses standard regular expressions to change a URI to a different URI. The supplied regular expression is matched against the URL, and if it matches, the server will substitute any parenthesized matches into the given string and use it as the URI. This is not a terminating directive. The server will use the new URI as input to Alias, Redirect or other MapMatch directives.

Parameter One: regex
  • The regex paramter is a regular expression that is matched against the URL. Subexpressions are grouped within parentheses. The parenthetically enclosed regular expressions will be substituted in a subsequent $n statement.
Parameter Two: URI
  • The URI paramater is any valid URI that is supported on the IBM i server. If there is a $ symbol (followed by a digit) that is not a substitution variable in the URI parameter, or there is an & symbol in the URI parameter that is part of the URI, the symbol must be escaped (\).

If the target URI is /www/apache/icons\&gifs/ the & would need to be escaped as follows on the MapMatch directive:

MapMatch ^/icons(.*) /www/apache/icons\&gifs/

If the target URI is /www/apache/icon$1/ the $ would need to be escaped as follows on the MapMatch directive:

MapMatch ^/icons(.*) /www/apache/icon\$1/ 

See Regular expression notation for HTTP Server for more information.

Redirect

Module: mod_alias
Syntax: Redirect [status] [url-path] url
Default: none
Context: server config, virtual host, directory, .htaccess
Override: FileInfo
Origin: Apache
Example: Redirect /service http://foo2.bar.com/service

The Redirect directive maps an old URL into a new one. The new URL is returned to the client, who then attempts to access the page with the new address. URL-path is a (%-decoded) path; any requests for documents beginning with this path will be returned with a redirect error to a new (%-encoded) URL beginning with url.

Parameter One: status
  • The status parameter is used to return the below HTTP status codes:
    Status Description
    permanent Returns a permanent redirect status (301) indicating that the resource has moved permanently.
    temp Returns a temporary redirect status (302). This is the default.
    seeother Returns a "See Other" status (303) indicating that the resource has been replaced.
    gone Returns a "Gone" status (410) indicating that the resource has been permanently removed. When this status is used the url argument should be omitted.

    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. 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, otherwise it must be omitted. Regardless, any HTTP status given must be known to HTTP Server.

Parameter Two: url-path
  • If the url-path has a trailing slash ('/'), the url should also have a trailing slash. If the url-path does not contain a trailing slash, the url should not either. Double check the designated url-path and the url, or a double-slash ('//') may appear in the resulting URL. The url-path must be an absolute path, not a relative path, even when used with .htaccess files or inside of <Directory> containers. The url-path must match the requested resource exactly or be a proper ancestor of it.
Parameter Three: url
  • The url parameter should be a complete URL string, including the scheme ('http://...') and the 'server:host' portion. When the status parameter is "gone", the url argument should be omitted.
Note: Redirect directives take precedence over Alias and ScriptAlias directives, regardless of their order in the configuration file. Redirect directives inside a Location take precedence over Redirect and Alias directives with an URL-path.

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>

RedirectMatch

Module: mod_alias
Syntax: RedirectMatch [status] regex url
Default: none
Context: server config, virtual host, directory, .htaccess
Override: FileInfo
Origin: Apache
Example: RedirectMatch (.*)\.gif$ http://www.anotherserver.com$1.jpg

This directive is equivalent to Redirect, but makes use of standard regular expressions, instead of simple prefix matching. The supplied regular expression is matched against the URL, and if it matches, the server will substitute any parenthesized matches into the given string and use it as a filename.

Parameter One: status
  • The status parameter is used to return the below HTTP status codes:
    Status Description
    permanent Returns a permanent redirect status (301) indicating that the resource has moved permanently.
    temp Returns a temporary redirect status (302). This is the default.
    seeother Returns a "See Other" status (303) indicating that the resource has been replaced.
    gone Returns a "Gone" status (410) indicating that the resource has been permanently removed. When this status is used the url argument should be omitted.

    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. 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, otherwise it must be omitted. Regardless, any HTTP status given must be known to HTTP Server.

Parameter Two: regex
  • The regex parameter is aregular expression that is matched against the URL. Subexpressions are grouped within parentheses. Then, parenthetically enclosed regular expressions will be substituted in a subsequent $n statement.
Parameter Three: url
  • The url parameter should be a complete URL string, including the scheme ('http://...') and the 'server:port' portion. If there is a $ symbol (followed by a digit) that is not a substitution variable in the url parameter, or there is a & symbol in the url parameter that is part of the URL, the symbol must be escaped (\).

If the URL to redirect to is http://www.anotherserver.com/cgi-bin/welcome.cgi?parm1=login&parm2=mainlist the & would need to be escaped as follows on the RedirectMatch directive:

RedirectMatch(.*) http://www.anotherserver.com/cgi-bin/welcome.cgi?parm1=login\&parm2=mainlist

If the URL to redirect to is http://www.anotherserver.com/htdocs/welcome$2login.html the $2 would need to be escaped as follows on the RedirectMatch directive:

RedirectMatch (.*)  http://www.anotherserver.com/htdocs/welcome\$2login.html

See Regular expression notation for HTTP Server for more information.

RedirectPermanent

Module: mod_alias
Syntax: RedirectPermanent url-path url
Default: none
Context: server config, virtual host, directory, .htaccess
Override: FileInfo
Origin: Apache
Example: RedirectPermanent /payroll http://payroll.server.com/payroll

The RedirectPermanent directive notifies the client that the Redirect is permanent (status 301). This is the exact equivalent to Redirect permanent.

Parameter One: url-path
  • The url-path parameter is any valid URL path. If you include a trailing '/' in the URL path, then the server will require a trailing '/' in order to expand the alias. That is, if you use 'Alias /icons/ /www/images/i/icons/' then the URL '/icon' will not be aliased.
Parameter Two: url
  • The url parameter should be a complete URL string, including the scheme ('http://...') and the 'server:host' portion. When the status parameter is "gone", the url argument should be omitted.

See Regular expression notation for HTTP Server for more information.

RedirectTemp

Module: mod_alias
Syntax: RedirectTemp url-path url
Default: none
Context: server config, virtual host, directory, .htaccess
Override: FileInfo
Origin: Apache
Example: RedirectTemp /service http://foo2.bar.com/service

The RedirectTemp directive notifies the client that the Redirect is only temporary (status 302). This is the exact equivalent to Redirect temp.

Parameter One: url-path
  • The url-path parameter is any valid URL path. If you include a trailing '/' in the URL path, then the server will require a trailing '/' in order to expand the alias. That is, if you use 'Alias /icons/ /www/images/i/icons/' then the URL '/icon' will not be aliased.
Parameter Two: url
  • The url parameter should be a complete URL string, including the scheme ('http://...') and the 'server:host' portion. When the status parameter is "gone", the url argument should be omitted.

See Regular expression notation for HTTP Server for more information.

ScriptAlias

Module: mod_alias
Syntax: ScriptAlias [url-path ] file-path | directory-path
Default: none
Context: server config, virtual host
Override: none
Origin: Apache
Example: ScriptAlias /cgi-bin/ /web/cgi-bin/
Example: ScriptAlias /cgi-bin/ /QSYS.LIB/QSYSCGI.LIB/

The ScriptAlias directive has the same behavior as the Alias directive, except that in addition it marks the target directory as containing CGI scripts, and then executes the CGI program. URLs with a (%-decoded) path beginning with url-path will be mapped to scripts beginning with directory-filename. Additional <Directory> containers that cover the destination of the ScriptAlias may need to be specified. Aliasing occurs before <Directory> containers are checked, so only the destination of Aliases are affected.

Parameter One: url-path
  • The url-path parameter is any valid url-path. It must end with a slash ('/') character so that any files in the directory will be routed.
Parameter Two: file-path | directory-path
  • The file-path | directory-path parameter is any valid directory/filename on the IBM i server.
Note: If the URL ends in a slash ("/") character, the ScriptAlias must also end in a slash character.

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}.pgm"
</LocationMatch>

ScriptAliasMatch

Module: mod_alias
Syntax: ScriptAliasMatch regex directory-filename
Default: none
Context: server config, virtual host
Override: none
Origin: Apache
Example: ScriptAliasMatch ^/cgi-bin/(.*)\.cgi /QSYS.LIB/QSYSCGI.LIB/$1.PGM

This directive is equivalent to ScriptAlias, but makes use of standard regular expressions, instead of simple prefix matching. The supplied regular expression is matched against the URL, and if it matches, the server will substitute any parenthesized matches into the given string and use it as a filename.

Parameter One: regex
  • The regex parameter is a regular expression that is matched against the URL. Subexpressions are grouped within parentheses. Then, parenthetically enclosed regular expressions will be substituted in a subsequent $n statement.
Parameter Two: directory-filename
  • This is any valid directory/filename that is supported on the IBM i server. If there is a $ symbol (followed by a digit) that is not a substitution variable in the directory-filename parameter, or there is a & symbol in the directory-filename parameter that is part of the directory or filename, the symbol must be escaped (\).

If the directory-filename is /usr/local/apache/cgi-bin&sym/$1.pgm, where the $1 is a substitution variable, the & would need to be escaped as follows on the ScriptAliasMatch directive:

ScriptAliasMatch ^/cgi-bin/(.*)\.cgi /usr/local/apache/cgi-bins\&sym/$1.pgm

If the directory-filename is /usr/local/apache/cgi-bin$2sym/ $1.pgm, where the $1 is a substitution variable, the $2 would need to be escaped as follows on the ScriptAliasMatch directive:

ScriptAliasMatch ^/cgi-bin/(.*)\.cgi /usr/local/apache/cgi-bin\$2sym/$1.pgm