Condition with path_reg and map_reg with regexp

Currently, I have a bunch of rules in haproxy.cfg like this:

frontend frontend-https
bind 10.30.1.120:443
redirect prefix http://customerwebapp.com/redir.jsp?customer_domain_id=123 code 301 if { hdr(host) -m sub example.com
}
default_backend backend-https

but I want to integrate a map file and take all the rules sets out with something like this:

frontend frontend-https
bind 10.30.1.120:443
redirect prefix (%[req.hdr(host),lower,map_reg(/etc/haproxy/redirect.map)] code 301

}
default_backend backend-http

and the file would contain something like this
(\w..)?.customer.com(.) https://webapp.com/redir.jsp?customer_domain_id=123

I know it’s missing the conditional, “if { hdr(host) -m sub example.com” but I’m not sure how to integrate them.

https://webapp.com/redir.jsp?customer_domain_id=123 is not really a prefix, I assume you are going to use the correct redirect keyword in your real configuration.

You need to work with http-request redirect here instead.

Something like:

http-request redirect location %[req.hdr(host),lower,map_reg(/etc/haproxy/redirect.map)]
1 Like

Thank you so much, Lukas!