Redirect with original url as encoded parameter


#1

I have the following configuration setup which works fine:

frontend http-in
    bind *:80
    mode http
    option  http-server-close
    option  forwardfor
    option  httplog

    acl redirect_domain hdr(Host) -i example1.com
    acl redirect_domain hdr(Host) -i example2.com
    acl redirect_domain hdr(Host) -i example3.com
    http-request redirect location https://my-new-domain.com/ code 302 if redirect_domain 

    default_backend web_default

This redirects my example[1-3].com to my-new-domain.com with a 302 redirect (Yes, I want the 302).
Now what I want to achieve is passing the original url to the “my-new-domain.com”, but the problem is that the URL won’t be encoded:

http-request redirect location https://my-new-domain.com/?referer=%[hdr(host)]%[url] code 302 if redirect_domain

This results in the URL to be build like:

https://my-new-domain.com/?referer=example1.com/requested-path/?param1&param2=248

While it should look like:

https://my-new-domain.com/?referer=example1.com%2Frequested-path%2F%3Fparam1%26param2%3D248

Is there any way how I can get HAProxy to apply url encoding to my referer param?