If you are having problems using conditions, here are some common things to look for.
Check the Apply if field for if statements
Most problems with conditions occur in the Apply if parameter because it uses logical expressions to represent actual VCL variables that specify when a condition should be applied to a configuration object. If you are having problems using conditions, start by checking to see if you've put an
if () statement in the wrong place. A condition's if statement is implied and doesn't need to be placed in the Apply if field of the condition window. You only need to type an evaluated expression (e.g.,
req.url ~ "^/special/").
Check the construction of inverse regex matches
Consider if inverse regular expression (regex) matching might be the issue, especially if you're using it to exclude a particular URL in your condition. When using the
!~ (inverse regex match) to build expressions that exclude particular URLs, be thoughtful when also using the
&& operators and multiple patterns.
For example, if you want to apply something to all URLs except those that start with
/admin, the condition you'd enter into the Apply if field would be
req.url !~ "^/admin". If you also wanted to exclude URLs starting with
/internal, that expression would be
!(req.url ~ "^/admin" || req.url ~ "^/internal").
TIP: Keep in mind De Morgan's laws if you're using multiple conditions and negation.
Check for general regex formatting mistakes
Consider the following general regex issues that may have caused trouble:
- Is case sensitivity the problem? Varnish regex is case sensitive by default. To use a case insensitive check, you must use the
- Have you escaped forward slashes? Forward slashes don't need to be escaped in Varnish regex.
Our cheatsheet provides additional examples of using VCL with regular expressions.