HAProxy community

HAProxy v2.2 change with %[url] variable including protocol

Since the commit here: http://git.haproxy.org/?p=haproxy.git;a=commit;h=30ee1efe676e8264af16bab833c621d60a72a4d7

…which added the protocol to the %[url] variable, the previous haproxy 1.8 configs I had working no longer function on v2.2(.2).

I’m looking for a suggestion of how best to complete both a redirect from http to https and a naked domain to www in a single line.

Previously this was accomplished as follows under v1.8 and worked well:
http-request set-var(req.scheme) str(https)
http-request redirect code 301 location %[var(req.scheme)]://www.domainname.com%[url] if { hdr(host) -i domainname.com }

For v1.8, a user browsing to https://domainname.com/path/or?query=whatever is successfully redirected to https://www.domainname.com/path/or?query=whatever

However on v2.2 the same implementation of %[url] results in the user getting: https://www.domainname.comhttps//domainname.com/path/or?query=whatever

What variables should be referenced to accomplish this?

Hi,

starting with haproxy 2.2.3 you can use the pathq sample fetch.

http-request redirect code 301 location %[var(req.scheme)]://www.domainname.com%[pathq] if { hdr(host) -i domainname.com }

before that you can use path, and the HQ log format notation.

http-request redirect code 301 location %[var(req.scheme)]://www.domainname.com%[path]%HQ if { hdr(host) -i domainname.com }

thank you for that. I have tested with v2.2.3 and the pathq appears to be what I’m after.
I’ll look into scheduling an upgrade to this version.
Thanks!