You are viewing a plain text version of this content. The canonical link for it is here.
Posted to docs@httpd.apache.org by bu...@apache.org on 2026/05/21 11:00:48 UTC
[Bug 70061] New: RewriteRule Directive: "!" (no match) modifier confused with Pattern
https://bz.apache.org/bugzilla/show_bug.cgi?id=70061
Bug ID: 70061
Summary: RewriteRule Directive: "!" (no match) modifier
confused with Pattern
Product: Apache httpd-2
Version: 2.5-HEAD
Hardware: All
URL: https://httpd.apache.org/docs/trunk/en/mod/mod_rewrite
.html#rewriterule
OS: All
Status: UNCONFIRMED
Severity: minor
Priority: P3
Component: Documentation
Assignee: docs@httpd.apache.org
Reporter: chealer@gmail.com
Target Milestone: ---
The documentation of the RewriteRule directive specifies the Syntax as follows:
> RewriteRule Pattern Substitution [flags]
Pattern is then specified as a PCRE regex.
But when the second argument starts with an exclamation mark ("!"), it is
interpreted as a modifier, so that the rule triggers when the pattern does
*not* match:
https://github.com/apache/httpd/blob/cfb8882f04b1c986656f6b19c487ab27810071b9/modules/mappers/mod_rewrite.c#L4029-L4035
There is some confusion because some think the character is included in the
pattern. Therefore, the remainder of the section assumes there is a match:
> $0 refers to the entire string matched by the Pattern, while $1..$9 refer to the corresponding captured groups from the matched Pattern.
In fact, all back-references to the first argument are (obviously) only
available when the pattern has as least 1 match.
The patch for issue #70024 (mostly) fixes that (and more), but does not address
the issue in RewriteCond (which assumes matches of both Pattern and
CondPattern).
đź…🄍: https://www.philippecloutier.com/Common+infrastructure+licensing#its
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: docs-unsubscribe@httpd.apache.org
For additional commands, e-mail: docs-help@httpd.apache.org
[Bug 70061] RewriteRule Directive: "!" (no match) modifier confused with Pattern
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=70061
--- Comment #6 from Philippe Cloutier <ch...@gmail.com> ---
(In reply to Rich Bowen from comment #5)
> The topic mentioned in the title of this ticket has been addressed. [!] has
> been called out as an optional component of the argument, and the
> consequence of providing it has been documented.
Yes, I could see that your change mostly fixes.
> The phrase that you reference:
>
> > The Substitution of a rewrite rule is the string that replaces the original URL-path that was matched by Pattern.
>
> I am unclear how that relates to this ticket, and would appreciate some
> explanation as to what this has to do with it, or what change it is that you
> are requesting. Can you please elaborate, or open a new ticket if it's a
> separate issue?
Modelizing issues and representing them with tickets is non-trivial. The same
issues can be tracked with multiple sets of tickets. A regression in a network
method could be tracked with 1 technical ticket about the method, or 10
user-oriented bug reports tracking each affected feature.
The angle this ticket takes is to report the mental model used to write the
document, and which the documentation consequently conveys, i.e. that an
initial "!" was part of the pattern. Therefore, this tracks all consequences of
that misunderstanding, including the incorrect synopsis, the incorrect
description of patterns, and the assumption that the rule triggers if and only
if the pattern has at least 1 match.
> If you could answer the above question -- what it is, exactly, that you
> object to about that phrase -- I'll attempt to address it.
The main flaws in that sentence are in its implication that the pattern of a
triggered rule matches the original URL-path. There are several things wrong
with that implication, as explained in ticket #70024, but the one tracked here
is the assumption that the pattern always matches. In negative rules (those
with "!" before the pattern), the main condition is that the pattern does not
match.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: docs-unsubscribe@httpd.apache.org
For additional commands, e-mail: docs-help@httpd.apache.org
[Bug 70061] RewriteRule Directive: "!" (no match) modifier confused with Pattern
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=70061
--- Comment #2 from Rich Bowen <rb...@apache.org> ---
The pattern either matches, or it does not. Regex does not have a concept of
"at least one match." It's either 1 or 0, and backreferences are only defined
if there is a match.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: docs-unsubscribe@httpd.apache.org
For additional commands, e-mail: docs-help@httpd.apache.org
[Bug 70061] RewriteRule Directive: "!" (no match) modifier confused with Pattern
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=70061
Rich Bowen <rb...@apache.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|REOPENED |RESOLVED
--- Comment #11 from Rich Bowen <rb...@apache.org> ---
Fixed in r1935194 (trunk) and r1935195 (2.4).
The Substitution opening sentence no longer implies that Pattern always matches
when a rule fires, and now cross-references the "What is matched?" section for
context on what the URL-path is in various contexts.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: docs-unsubscribe@httpd.apache.org
For additional commands, e-mail: docs-help@httpd.apache.org
[Bug 70061] RewriteRule Directive: "!" (no match) modifier confused with Pattern
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=70061
--- Comment #7 from Rich Bowen <rb...@apache.org> ---
(In reply to Philippe Cloutier from comment #6)
> > If you could answer the above question -- what it is, exactly, that you
> > object to about that phrase -- I'll attempt to address it.
> The main flaws in that sentence are in its implication that the pattern of a
> triggered rule matches the original URL-path. There are several things wrong
> with that implication, as explained in ticket #70024, but the one tracked
> here is the assumption that the pattern always matches. In negative rules
> (those with "!" before the pattern), the main condition is that the pattern
> does not match.
No, I simply don't agree that it implies that. It states "replaces the original
URL-path that was matched by Pattern" - thus, when there is no match, there is
no replacement.
Willing to consider a patch, if you feel that you have a rephrasing that helps
your confusion, but I do not see any cause for confusion here.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: docs-unsubscribe@httpd.apache.org
For additional commands, e-mail: docs-help@httpd.apache.org
[Bug 70061] RewriteRule Directive: "!" (no match) modifier confused with Pattern
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=70061
Philippe Cloutier <ch...@gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |REOPENED
Resolution|FIXED |---
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: docs-unsubscribe@httpd.apache.org
For additional commands, e-mail: docs-help@httpd.apache.org
[Bug 70061] RewriteRule Directive: "!" (no match) modifier confused with Pattern
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=70061
--- Comment #10 from Philippe Cloutier <ch...@gmail.com> ---
Hi Rich,
(In reply to Rich Bowen from comment #9)
> Your example demonstrates, rather than contradicts, my assertion.
Eh, no.
You asserted that “when there is no match, there is no replacement.”
Do you recognize that “/games” contains no match for “work$”? regexr.com/8n6vm
> I take your final statement as saying that this issue is now resolved, by the patch
> that was previously applied from another ticket.
No, the patch in question is the one for #70024, which has not been applied,
and the issue persists.
> If that is not the case, please do feel free to open a new ticket that
> addresses just the one narrow problem you believe still exists. This ticket
> seems to have drifted from its title statement - which has been addressed -
> that I'm no longer sure what it's about.
I don't see how this ticket would have drifted.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: docs-unsubscribe@httpd.apache.org
For additional commands, e-mail: docs-help@httpd.apache.org
[Bug 70061] RewriteRule Directive: "!" (no match) modifier confused with Pattern
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=70061
--- Comment #1 from Rich Bowen <rb...@apache.org> ---
This ticket seems to discuss two separate things - the presence (or absence) of
the ! character in the rewriterule pattern, and RewriteCond patterns. Right?
But then it also talks about backreferences. Trying to disambiguate all of the
isssues addressed here.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: docs-unsubscribe@httpd.apache.org
For additional commands, e-mail: docs-help@httpd.apache.org
[Bug 70061] RewriteRule Directive: "!" (no match) modifier confused with Pattern
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=70061
--- Comment #8 from Philippe Cloutier <ch...@gmail.com> ---
(In reply to Rich Bowen from comment #7)
> No, I simply don't agree that it implies that. It states "replaces the
> original URL-path that was matched by Pattern" - thus, when there is no
> match, there is no replacement.
In fact, when the second argument starts with a "!", there is:
https://htaccess.madewithlove.com?share=245ff512-b608-42f4-a6ab-6a8fd58b3651
> Willing to consider a patch, if you feel that you have a rephrasing that
> helps your confusion, but I do not see any cause for confusion here.
The patch previously mentioned fixes that part.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: docs-unsubscribe@httpd.apache.org
For additional commands, e-mail: docs-help@httpd.apache.org
[Bug 70061] RewriteRule Directive: "!" (no match) modifier confused with Pattern
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=70061
Rich Bowen <rb...@apache.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEEDINFO
Ever confirmed|0 |1
--- Comment #3 from Rich Bowen <rb...@apache.org> ---
I'm reasonably sure that everything that this ticket mentions was addressed in
r1934480 and r1934481.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: docs-unsubscribe@httpd.apache.org
For additional commands, e-mail: docs-help@httpd.apache.org
[Bug 70061] RewriteRule Directive: "!" (no match) modifier confused with Pattern
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=70061
--- Comment #4 from Philippe Cloutier <ch...@gmail.com> ---
(In reply to Rich Bowen from comment #1)
> This ticket seems to discuss two separate things - the presence (or absence)
> of the ! character in the rewriterule pattern, and RewriteCond patterns.
> Right?
Not really. The documentation is confused about the special characters (in
particular "!") used at the beginning of the arguments of RewriteCond and
RewriteRule which contain patterns. It considers these characters as part of
the pattern, and therefore, that a condition is only satisfied when the pattern
matches. This confusion is evident in several places.
> But then it also talks about backreferences. Trying to disambiguate
> all of the isssues addressed here.
I fail to see the ambiguity here. The specification of back-references is just
one place which assumes the pattern matches if the rule triggers.
(In reply to Rich Bowen from comment #2)
> The pattern either matches, or it does not. Regex does not have a concept of
> "at least one match." It's either 1 or 0, and backreferences are only
> defined if there is a match.
Regular expressions are complex. There are multiple dialects, libraries,
functions and modes, but in general, a pattern can have multiple matches in
“subject string”. If the pattern is "s", there is 1 match for [0→1] and another
for [8→9]. See pcre2demo(3) and its "-g" switch.
However, you are right that mod_rewrite does not find all of these; a positive
main condition is satisfied as soon as the subject-path has at least 1 matching
substring.
(In reply to Rich Bowen from comment #3)
> I'm reasonably sure that everything that this ticket mentions was addressed
> in r1934480 and r1934481.
Thank you once again Rich, but r1934480 does not fully fix. The section still
contains:
> The Substitution of a rewrite rule is the string that replaces the original URL-path that was matched by Pattern.
The patch fixes that.
By the way, the inability to restore the status (from NEEDINFO) is tracked in
INFRA-27948.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: docs-unsubscribe@httpd.apache.org
For additional commands, e-mail: docs-help@httpd.apache.org
[Bug 70061] RewriteRule Directive: "!" (no match) modifier confused with Pattern
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=70061
--- Comment #5 from Rich Bowen <rb...@apache.org> ---
The topic mentioned in the title of this ticket has been addressed. [!] has
been called out as an optional component of the argument, and the consequence
of providing it has been documented.
The phrase that you reference:
> The Substitution of a rewrite rule is the string that replaces the original URL-path that was matched by Pattern.
I am unclear how that relates to this ticket, and would appreciate some
explanation as to what this has to do with it, or what change it is that you
are requesting. Can you please elaborate, or open a new ticket if it's a
separate issue?
I see INFRA-27948 but I do, in fact, still NEEDINFO, as I don't understand what
it is that you're asking for.
If you could answer the above question -- what it is, exactly, that you object
to about that phrase -- I'll attempt to address it.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: docs-unsubscribe@httpd.apache.org
For additional commands, e-mail: docs-help@httpd.apache.org
[Bug 70061] RewriteRule Directive: "!" (no match) modifier confused with Pattern
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=70061
Rich Bowen <rb...@apache.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEEDINFO |RESOLVED
Resolution|--- |FIXED
--- Comment #9 from Rich Bowen <rb...@apache.org> ---
Your example demonstrates, rather than contradicts, my assertion. I take your
final statement as saying that this issue is now resolved, by the patch that
was previously applied from another ticket.
If that is not the case, please do feel free to open a new ticket that
addresses just the one narrow problem you believe still exists. This ticket
seems to have drifted from its title statement - which has been addressed -
that I'm no longer sure what it's about. Tickets about one single issue are
much easier to discern whether they're completed.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: docs-unsubscribe@httpd.apache.org
For additional commands, e-mail: docs-help@httpd.apache.org