Fastly’s request condition is applied to the last matching condition

If you want Fastly to switch origin (backend) according to a condition, you can do so by setting a request condition.
I misunderstood the behavior of the request condition and got into trouble, so I’ll show you what I misunderstood and how I dealt with it.

Request condition

The Request condition has a priority, and the default is 10. The lower the value, it will be evaluated first, and all request conditions will be evaluated.
The following is an example of a request condition.

  • Request condition 1
    • priority: 10
    • condition: == "" && req.url.path ~ "^/v2"
    • backend:
  • Request condition 2
    • priority: 20
    • condition: == ""
    • backend:

With this configuration, I thought that a request for would set the backend to and a request for would set the backend to
However, the backend for was set to
This is because the request conditions are evaluated in ascending order of priority, but matching the conditions does not stop them from being evaluated.
The above request conditions are VCL as follows.

# Request Condition: api_v2 Prio: 10 if( == "" && req.url.path ~ "^/v2/" ) { set req.backend = F_bar_example_com; } #end condition # Request Condition: api_v1 Prio: 20 if( == "" ) { set req.backend = F_foo_example_com; } #end condition
Code language: PHP (php)

If statements are generated as there are request conditions. if a condition with a high priority value is matched, the backend will be that one.
When setting the request conditions, you must be aware of one of the following:

  • Set a condition that does not match more than one request condition
  • Set priorities appropriately to ensure that multiple request conditions match the intended behavior

Leave a Reply