From: Rich Bowen Date: Fri, 15 May 2026 15:23:39 +0000 (+0000) Subject: Consolidates advice about crafting regular expressions in one place, X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=01599340dfe7ca601c67087ab259e10c039f350a;p=thirdparty%2Fapache%2Fhttpd.git Consolidates advice about crafting regular expressions in one place, rather than having it duplicated in two docs. Gives example of using ! to negate a match, and notes that in the event of a not-match, backreferences are not defined (because they didn't match) and points to the backrefs section for further discussion. Note that there's still probably a case to be made for a separate regular expression reference, since neither `man perlre` nor Jeffrey's book are likely to be in the possession of our audience. (References patch on bz#70024 but takes it rather a different direction, since that patch was not accurate.) git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1934224 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/docs/manual/mod/mod_rewrite.xml b/docs/manual/mod/mod_rewrite.xml index 6af6d95bb5..44f5de8acb 100644 --- a/docs/manual/mod/mod_rewrite.xml +++ b/docs/manual/mod/mod_rewrite.xml @@ -1198,26 +1198,11 @@ sections and consider both set of statements, rather than only the last one. -

For some hints on regular - expressions, see - the mod_rewrite - Introduction.

- -

In mod_rewrite, the NOT character - ('!') is also available as a possible pattern - prefix. This enables you to negate a pattern; to say, for instance: - ``if the current URL does NOT match this - pattern''. This can be used for exceptional cases, where - it is easier to match the negative pattern, or as a last - default rule.

- -Note -When using the NOT character to negate a pattern, you cannot include -grouped wildcard parts in that pattern. This is because, when the -pattern does NOT match (ie, the negation matches), there are no -contents for the groups. Thus, if negated patterns are used, you -cannot use $N in the substitution string! - +

For information on regular + expressions, including the use of the + ! prefix to negate a pattern, see the + Regular Expressions + section of the mod_rewrite introduction.

The Substitution of a rewrite rule is the string that replaces the original URL-path that diff --git a/docs/manual/rewrite/intro.xml b/docs/manual/rewrite/intro.xml index e35646b9a1..9132a53ca9 100644 --- a/docs/manual/rewrite/intro.xml +++ b/docs/manual/rewrite/intro.xml @@ -165,11 +165,23 @@ well as write your own.

not c/t -

In mod_rewrite the ! character can be +

The ! (Not) character can be used before a regular expression to negate it. This is, a string will be considered to have matched only if it does not match the rest of the expression.

+

When using ! to negate a pattern, note that +backreferences (e.g. +$1, $2) are not available, since the +pattern does not match.

+ +

For example, the following will redirect any request that does +not start with /admin

+ + +RewriteRule "!^/admin" "/xyz.html" [R,L] + +
Regex Back-Reference Availability