Hi Bjoern. On 18.01.20 14:02, [email protected] wrote:
Am Samstag, 18. Januar 2020 schrieb Aleksandar Lazic <[email protected] <mailto:[email protected]>>:Hi. On 18.01.20 13:11, [email protected] <mailto:[email protected]> wrote: Hi, i want to redirect the following (the value of the code param should be rewritten): abc.de/?v=1&code=1530&b=3 <http://abc.de/?v=1&code=1530&b=3> -> abc.de/?v=1&code=6780&b=3 <http://abc.de/?v=1&code=6780&b=3> abc.it/?v=2&code=2400&b=2 <http://abc.it/?v=2&code=2400&b=2> -> abc.it/?v=2&code=7150&b=2 <http://abc.it/?v=2&code=7150&b=2> abc.fr <http://abc.fr> .. abc.se <http://abc.se> .. . . When i don't use maps, i can accomplish the task with the following lines (but this needs many of those lines): http-request set-header X-Redirect-Url %[url,regsub(code=1530,code=6780,g)] if { hdr_reg(host) -i ^abc\.de$ } http-request set-header X-Redirect-Url %[url,regsub(code=2400,code=7150,g)] if { hdr_reg(host) -i ^abc\.it$ } http-request redirect code 302 location https://%[hdr(host)]%[hdr(X-Redirect-Url)] But i want to use map files to reduce duplication and make it easier to add new items. I have these map files (domain is the lookup key): desktop_ids.map: abc.de <http://abc.de> 1530 abc.it <http://abc.it> 2400 . . mobile_ids.map: abc.de <http://abc.de> 6780 abc.it <http://abc.it> 7150 . . http-request set-header X-ID-Desktop %[hdr(host),lower,map_str(/etc/haproxy/desktop_ids.map)] http-request set-header X-ID-Mobile %[hdr(host),lower,map_str(/etc/haproxy/mobile_ids.map)] What i would need is the following: http-request set-header X-Redirect-Url %[url,regsub(code=%[hdr(X-ID-Desktop)],code=%[hdr(X-ID-Mobile)],g)] http-request redirect code 302 location https://%[hdr(host)]%[hdr(X-Redirect-Url)] But that's not possible, you cannot use variables in the regex or substitution field of regsub. I've also tried "http-request replace-header", but same problem, you cannot use variables for the "match-regex". Maybe is it possible to cut the "code" param from the query string and append it with the new value to the query string. But this needs some complex regex and handling of multiple conditions in query string (plus ordering of query string params is different than). Is there a possibility to use variables in regsub or in the "match-regex" of replace-header? I think you will need a small lua action handler which do the job. In the blog post are some examples which can help you to reach your target. https://www.haproxy.com/blog/5-ways-to-extend-haproxy-with-lua/ <https://www.haproxy.com/blog/5-ways-to-extend-haproxy-with-lua/> Maybe you can start with the example on stackoverflow and add the map handling into the code. https://stackoverflow.com/questions/50844292/how-to-make-ha-proxy-to-follow-redirects-by-itself/50872246#50872246 <https://stackoverflow.com/questions/50844292/how-to-make-ha-proxy-to-follow-redirects-by-itself/50872246#50872246> https://www.arpalert.org/src/haproxy-lua-api/2.0dev/index.html#map-class <https://www.arpalert.org/src/haproxy-lua-api/2.0dev/index.html#map-class> It would be interesting to know which haproxy version do you use. haproxy -vv Best regards / Mit freundlichen Grüßen Bjoern Hth Aleks Hi Aleks, i'm using HAProxy 1.8. I wanted to avoid using lua for "only" doing some redirects. I was searching for a native method in HAProxy. All "building blocks" are present, except that you cannot use variables in the match-regex etc. (or maybe there is possibility?)
I don't know any possibilities without lua, maybe someone else on the ML. Do you see any chance to update to 2.1 with lua? Please keep the ML in the loop, thanks.
Bjoern
Best regards Aleks

