Bug 63608 - Negative pattern match in rewrite rule is not as documented
Summary: Negative pattern match in rewrite rule is not as documented
Alias: None
Product: Tomcat 8
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 8.5.x-trunk
Hardware: All All
: P2 normal (vote)
Target Milestone: ----
Assignee: Tomcat Developers Mailing List
Depends on:
Reported: 2019-07-24 19:11 UTC by michaelc
Modified: 2019-07-29 14:42 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description michaelc 2019-07-24 19:11:58 UTC
The mention of using "NOT character ('!')" in rule patterns as negative match no longer matches implementation:


    In the rules, 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.

The current implementation uses java.util.regex, which does not support a simple ! prefix as a negative match regex:


Instead, you need to use zero-width lookahead like this (to match any URL but /portal/api/.*)


This inaccurate documentation exist in all versions, at least since 8.0.x. For backward compatibility to the above documentation, RewriteRule needs the `positive` variable and logic found in the RewriteCond class.
Comment 1 Mark Thomas 2019-07-29 14:42:04 UTC
Thanks for the report.

Fixed in:
- master for 9.0.23 onwards
- 8.5.x for 8.5.44 onwards

The RewriteValve is not present in 7.0.x