From 8cd7ce41fc82194368182efe2bcfea122c8a03ab Mon Sep 17 00:00:00 2001 From: Daniel Earl Poirier Date: Mon, 14 Dec 2009 18:50:30 +0000 Subject: [PATCH] Expand on mod_alias documentation. Add a link from the glossary entry on regular expressions to the wikipedia page that seems to be a good reference for the syntax of PCRE's flavor of regular expressions. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@890436 13f79535-47bb-0310-9956-ffa450edef68 --- docs/manual/glossary.xml | 4 +- docs/manual/mod/mod_alias.xml | 84 ++++++++++++++++++++++++++++++++++- 2 files changed, 86 insertions(+), 2 deletions(-) diff --git a/docs/manual/glossary.xml b/docs/manual/glossary.xml index c85d817483..d6d842a84f 100644 --- a/docs/manual/glossary.xml +++ b/docs/manual/glossary.xml @@ -382,7 +382,9 @@ - for example, all .gif and .jpg files under any "images" directory could be written as "/images/.*(jpg|gif)$". Apache uses Perl Compatible Regular Expressions provided by the PCRE library. + href="http://www.pcre.org/">PCRE library. You can find more documentation + about PCRE's regular expression syntax at that site, or at + Wikipedia.
Reverse Proxy
diff --git a/docs/manual/mod/mod_alias.xml b/docs/manual/mod/mod_alias.xml index e58633722c..9e4717d445 100644 --- a/docs/manual/mod/mod_alias.xml +++ b/docs/manual/mod/mod_alias.xml @@ -180,13 +180,65 @@ expressions AliasMatch ^/icons(.*) /usr/local/apache/icons$1 -

It is also possible to construct an alias with case-insensitive +

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:

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

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 +
+ @@ -307,6 +359,17 @@ of the current URL RedirectMatch (.*)\.gif$ http://www.anotherserver.com$1.jpg + +

The considerations related to the difference between + Alias and + AliasMatch + also apply to the difference between + Redirect and + RedirectMatch. + See AliasMatch for + details.

+ + @@ -443,6 +506,25 @@ and designates the target as a CGI script ScriptAliasMatch ^/cgi-bin(.*) /usr/local/apache/cgi-bin$1 + +

As for AliasMatch, 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:

+ + + ScriptAliasMatch (?i)^/cgi-bin(.*) /usr/local/apache/cgi-bin$1 + + +

The considerations related to the difference between + Alias and + AliasMatch + also apply to the difference between + ScriptAlias and + ScriptAliasMatch. + See AliasMatch for + details.

+ -- 2.40.0