Condition with path_reg and map_dom with regexps


I’d like to match a sample (path) with a regular expression read from a map (with hdr(host) as a key). Is this possible somehow?

Example: Given a request with hdr(host) set to ‘’ and path set to /bar I’d like to have a map file like this: ^/bar/.*

I posted basically the same question on stackoverflow before I found this community.

Thanks in advance

base contains a concatenation of hostname and path, that is what you want to match your map file against, it’s impossible to do so with 2 different variables (hostname AND path).

Then you can use string matches, substring matches or even regex - whatever you want, but against a single string.

$ cat /etc/haproxy/ foo

Exact string match:

use_backend bk-%[base,lower,map_str(/etc/haproxy/,bk_default)]

“beg” string match:

use_backend bk-%[base,lower,map_beg(/etc/haproxy/,bk_default)]

Or differently, you really need a regexp:

$ cat /etc/haproxy/|bob/|alice/) foo

use_backend bk-%[base,lower,map_reg(/etc/haproxy/,bk_default)]

Configs are untested, but you get the point.

1 Like