Http-request redirect with map file and query

Hello everyone.

I am trying to redirect our legacy sites to a secondary site. I have tried various configurations and I cannot get it to work with a map file. I am able to hard code the entries, and it works. But as the entries are adding up it is becoming increasingly difficult (as you can imagine).

My legacy.map file contains single entries. Basically part of the query string.

cst=8484-29384-1123-48483
cst=4987-63254-987-1547-87
cst=159-98778-6364-15987

You get the idea.

My haproxy.cfg contains a ton of settings I’ve experimented with (commented out over time). Here is the one I am hoping to get the complete result from.

This is on the (only) frontend.

http-request redirect location https://mypage.com/alternate-site.html code 301 if { query map(/etc/haproxy/legacy.map) -m found }

If I do

http-request redirect location https://mypage.com/alternate-site.html code 301 if { query cst=1256-9874-4848-7898 -m found }

it works. But, as we increase these over time, that is going to become a burden to maintain.

Any thoughts or experience with this type of work? I have gone from HAProxy 1.5 to 2.0, but I am still encountering issues with this. Not sure what I’m doing wrong, but it looks like the values in the map file are being ignored.

It’s possible I just don’t understand how the mapping works? Can anyone share an example as to how a map file is supposed to look with a query string and a redirect?

Solution! Walking away for a few days seemed to help:

http-request redirect location %[hdr(host),map(/etc/haproxy/redirect.map)]/mypath.html code 301 if { query,map_reg(/etc/haproxy/redirect.map) -m found }

This works for the appropriate queries that are in the redirect.map file.

w00t! :tada:

Thank you for providing a scratch pad for me to brainstorm this all out :wink:

1 Like