Hi,

i want to redirect the following (the value of the code param should be
rewritten):

abc.de/?v=1&code=1530&b=3    ->   abc.de/?v=1&code=6780&b=3
abc.it/?v=2&code=2400&b=2      ->   abc.it/?v=2&code=7150&b=2
abc.fr ..
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 1530
abc.it 2400
.
.

mobile_ids.map:
abc.de 6780
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?


Best regards / Mit freundlichen Grüßen

Bjoern

Reply via email to