Skip to main content

URL match operators

Every rule matches the request URL using a single operator, selected with the matchType field. This is the one condition mechanism the rules engine ships today, and it is shared by both cache rules and header rules.

The operators

matchTypeUI labelBehavior
0EqualsThe request path equals the value exactly.
1ContainsThe value appears anywhere in the request path.
2Starts withThe request path begins with the value.
3Ends withThe request path ends with the value.
4Regex (advanced)The value is a PCRE regular expression evaluated by the edge.

Regex matching

Regex (matchType: 4) is a PCRE pattern evaluated by the edge via ngx.re. Case-insensitive matching uses the ~* style. Use it when the simpler operators are not expressive enough, for example matching a file extension regardless of a trailing query string:

\.mp4($|\?)
tip

Only reach for Regex when you actually need it. StartsWith, EndsWith, and Contains are cheaper to reason about and cover most cases (path prefixes, file extensions, and substrings respectively).

When the value is required vs. optional

The match value (the pattern field) behaves differently per rule type:

Rule typeMatch valueEmpty value means
Cache ruleRequiredn/a — a cache rule must specify what to match
Header ruleOptionalGlobal — the rule applies to every request

So a header rule with an empty pattern is a global rule that runs on all requests regardless of the operator. A cache rule always needs a value.

:::info Header rule default operator A header rule's matchType defaults to Contains (1) in both the API and the database. An empty pattern makes the rule global no matter which operator is set. :::

Limits

FieldLimit
pattern (match value)Maximum length 500 characters

Examples

Each example shows the pattern and matchType you would send.

Equals — match exactly one path:

{ "pattern": "/favicon.ico", "matchType": 0 }

Contains — match any path containing a substring:

{ "pattern": "/wp-admin/", "matchType": 1 }

StartsWith — match a path prefix (great for asset directories):

{ "pattern": "/static/", "matchType": 2 }

EndsWith — match a file extension:

{ "pattern": ".mp4", "matchType": 3 }

Regex — match an extension with an optional query string:

{ "pattern": "\\.mp4($|\\?)", "matchType": 4 }

:::note Legacy cache patterns Some older cache rules encode the operator as an nginx-style prefix inside the pattern (for example = /exact, ^~ /prefix/, ~ regex, ~* regex). The panel parses these automatically when you open such a rule for editing. Re-saving a case-insensitive (~*) legacy rule maps it to Regex and does not preserve case-insensitivity, so re-add (?i) or adjust the pattern if you need it. :::

Next steps

  • Cache rules — use these operators to scope TTL and cache features.
  • Header rules — use these operators to scope header changes.