HAProxy community

Haproxy not switching backends by using path_reg

Hello all,

I want to use different backends by using regex but it is not working as expected. My configuration like as shown below.

acl cons path_reg ^/(test)/([a-z-0-9]+/){0,1}$
use_backend consistent if cons

For example, this config should work like this:

https://domain.com/test --> should switch to consistent backend
https://domain.com/test/?a=1 --> should not switch to consistent backend but to default

how can i get it?

Thanks

Provide more examples please, I can’t tell what you are trying to achieve.

Hello,

I mean, if a url has query string then it should switch to default backend if does not it should switch to another backend that I defined as consistent. I want to achieve this situation by using path_reg.

You cannot achieve that with path, because the query string is not in path.

https://cbonte.github.io/haproxy-dconv/2.0/configuration.html#7.3.6-path

This extracts the request’s URL path, which starts at the first slash and
ends before the question mark (without the host part).

Use query instead, like acl cons -m found query.