]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Consolidates advice about crafting regular expressions in one place,
authorRich Bowen <rbowen@apache.org>
Fri, 15 May 2026 15:23:39 +0000 (15:23 +0000)
committerRich Bowen <rbowen@apache.org>
Fri, 15 May 2026 15:23:39 +0000 (15:23 +0000)
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

docs/manual/mod/mod_rewrite.xml
docs/manual/rewrite/intro.xml

index 6af6d95bb58b78bbb1f97a93b73c04c62d15e595..44f5de8acbbb2c28d99b58f588045657525ca4a0 100644 (file)
@@ -1198,26 +1198,11 @@ sections and consider both set of statements, rather than only the last one.</li
 </example>
 </note>
 
-      <p>For some hints on <glossary ref="regex">regular
-      expressions</glossary>, see
-      the <a href="../rewrite/intro.html#regex">mod_rewrite
-      Introduction</a>.</p>
-
-      <p>In <module>mod_rewrite</module>, the NOT character
-      ('<code>!</code>') is also available as a possible pattern
-      prefix. This enables you to negate a pattern; to say, for instance:
-      ``<em>if the current URL does <strong>NOT</strong> match this
-      pattern</em>''. This can be used for exceptional cases, where
-      it is easier to match the negative pattern, or as a last
-      default rule.</p>
-
-<note><title>Note</title>
-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 <code>$N</code> in the substitution string!
-</note>
+      <p>For information on <glossary ref="regex">regular
+      expressions</glossary>, including the use of the
+      <code>!</code> prefix to negate a pattern, see the
+      <a href="../rewrite/intro.html#regex">Regular Expressions</a>
+      section of the mod_rewrite introduction.</p>
 
       <p>The <a id="rhs" name="rhs"><em>Substitution</em></a> of a
       rewrite rule is the string that replaces the original URL-path that
index e35646b9a18363ed81a990ea942528f531aacb54..9132a53ca949e915f53a5e791315a231ba2fb9fb 100644 (file)
@@ -165,11 +165,23 @@ well as write your own.</p>
       not <code>c/t</code></td></tr>
 </table>
 
-<p>In <module>mod_rewrite</module> the <code>!</code> character can be
+<p>The <code>!</code> (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.</p>
 
+<p>When using <code>!</code> to negate a pattern, note that
+<a href="#InternalBackRefs">backreferences</a> (e.g.
+<code>$1</code>, <code>$2</code>) are not available, since the
+pattern does not match.</p>
+
+<p>For example, the following will redirect any request that does
+<em>not</em> start with <code>/admin</code></p>
+
+<highlight language="config">
+RewriteRule "!^/admin" "/xyz.html" [R,L]
+</highlight>
+
 </section>
 
 <section id="InternalBackRefs"><title>Regex Back-Reference Availability</title>