From dc6c78aea75b78f20db4e9099151d4be6a13c919 Mon Sep 17 00:00:00 2001 From: Christophe Jaillet Date: Sun, 1 Sep 2019 14:39:30 +0000 Subject: [PATCH] Fix PR 63713 reported by WJCarpenter: Add a small word about '\' which is used in the examples below. Add some missing links (, ) Improve some xml layout to have it readable. (r1866233 in trunk) + some trailing spaces removal and alignmed in examples to synch with trunk. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1866240 13f79535-47bb-0310-9956-ffa450edef68 --- docs/manual/rewrite/intro.xml | 125 +++++++++++++++++++++------------- 1 file changed, 78 insertions(+), 47 deletions(-) diff --git a/docs/manual/rewrite/intro.xml b/docs/manual/rewrite/intro.xml index 871e56e5da0..d0897fdc0d3 100644 --- a/docs/manual/rewrite/intro.xml +++ b/docs/manual/rewrite/intro.xml @@ -73,7 +73,7 @@ it will tell you exactly how each rule is processed.

Regular Expressions -

mod_rewrite uses the Perl Compatible +

mod_rewrite uses the Perl Compatible Regular Expression vocabulary. In this document, we do not attempt to provide a detailed reference to regular expressions. For that, we recommend the PCRE man pages, the @@ -103,32 +103,65 @@ well as write your own.

Example -.Matches any single -characterc.t will match cat, -cot, cut, etc. -+Repeats the previous match one or more -timesa+ matches a, aa, -aaa, etc -*Repeats the previous match zero or more -times.a* matches all the same things -a+ matches, but will also match an empty string. -?Makes the match optional. -colou?r will match color and colour. + + . + Matches any single character + c.t will match cat, cot, + cut, etc + + + + + Repeats the previous match one or more times + a+ matches a, aa, + aaa, etc + + + * + Repeats the previous match zero or more times + a* matches all the same things a+ matches, + but will also match an empty string + + + ? + Makes the match optional + colou?r will match color and + colour + + + \ + Escape the next character + \. will match . (dot) and not any single + character as explain above + + + ^ + Called an anchor, matches the beginning of the string + ^a matches a string that begins with a + + + $ + The other anchor, this matches the end of the string + a$ matches a string that ends with a + + + ( ) + Groups several characters into a single unit, and captures a match + for use in a backreference + (ab)+ matches ababab - that is, the + + applies to the group. For more on backreferences see + below -^Called an anchor, matches the beginning -of the string^a matches a string that begins with -a -$The other anchor, this matches the end of -the string.a$ matches a string that ends with -a. -( )Groups several characters into a single -unit, and captures a match for use in a backreference.(ab)+ -matches ababab - that is, the + applies to the group. -For more on backreferences see below. -[ ]A character class - matches one of the -charactersc[uoa]t matches cut, -cot or cat. -[^ ]Negative character class - matches any character not specifiedc[^/]t matches cat or c=t but not c/t + + [ ] + A character class - matches one of the characters + c[uoa]t matches cut, cot or + cat + + + [^ ] + Negative character class - matches any character not specified + c[^/]t matches cat or c=t but + not c/t

In mod_rewrite the ! character can be @@ -145,22 +178,22 @@ the expression.

CondPattern, back-references are internally created which can be used with the strings $N and %N (see below). These are available for creating - the Substitution parameter of a + the Substitution parameter of a RewriteRule or - the TestString parameter of a + the TestString parameter of a RewriteCond.

Captures in the RewriteRule patterns are (counterintuitively) available to - all preceding + >RewriteRule patterns are (counterintuitively) available to + all preceding RewriteCond directives, because the RewriteRule expression is evaluated before the individual conditions.

-

Figure 1 shows to which - locations the back-references are transferred for expansion as - well as illustrating the flow of the RewriteRule, RewriteCond - matching. In the next chapters, we will be exploring how to use - these back-references, so do not fret if it seems a bit alien +

Figure 1 shows to which + locations the back-references are transferred for expansion as + well as illustrating the flow of the RewriteRule, RewriteCond + matching. In the next chapters, we will be exploring how to use + these back-references, so do not fret if it seems a bit alien to you at first.

@@ -183,12 +216,12 @@ of three arguments separated by spaces. The arguments are

  • [flags]: options affecting the rewritten request.
  • -

    The Pattern is a regular expression. -It is initially (for the first rewrite rule or until a substitution occurs) -matched against the URL-path of the incoming request (the part after the -hostname but before any question mark indicating the beginning of a query -string) or, in per-directory context, against the request's path relative -to the directory for which the rule is defined. Once a substitution has +

    The Pattern is a regular expression. +It is initially (for the first rewrite rule or until a substitution occurs) +matched against the URL-path of the incoming request (the part after the +hostname but before any question mark indicating the beginning of a query +string) or, in per-directory context, against the request's path relative +to the directory for which the rule is defined. Once a substitution has occurred, the rules that follow are matched against the substituted value.

    @@ -289,7 +322,7 @@ argument is a list of flags that modify how the match is evaluated.

    different server, you could use:

    RewriteCond "%{REMOTE_ADDR}" "^10\.2\." -RewriteRule "(.*)" "http://intranet.example.com$1" +RewriteRule "(.*)" "http://intranet.example.com$1"

    When more than @@ -301,8 +334,8 @@ their query string, unless they also contain a cookie containing the word "go", you could use:

    RewriteCond "%{QUERY_STRING}" "hack" -RewriteCond "%{HTTP_COOKIE}" "!go" -RewriteRule "." "-" [F] +RewriteCond "%{HTTP_COOKIE}" !go +RewriteRule "." "-" [F]

    Notice that the exclamation mark specifies a negative match, so the rule is only applied if the cookie does not contain "go".

    @@ -315,7 +348,7 @@ will direct the request to a different directory depending on the hostname used to access the site:

    RewriteCond "%{HTTP_HOST}" "(.*)" -RewriteRule "^/(.*)" "/sites/%1/$1" +RewriteRule "^/(.*)" "/sites/%1/$1"

    If the request was for http://example.com/foo/bar, then %1 would contain example.com @@ -354,5 +387,3 @@ the RewriteRule. In addition, the - - -- 2.47.3