I'm redirecting to some domain based on an acl condition but I want the user to end up on either http
or https
depending on the scheme/protocol of their request. I've managed to do that with the 2 lines shown bellow, but I'd like to convert them to just 1 line:
http-request redirect code 301 location http://www.example.com%[url] if acl_whatever !{ ssl_fc }
http-request redirect code 301 location https://www.example.com%[url] if acl_whatever { ssl_fc }
Ideally I'd like to redirect to something like %[scheme]://www.example.com%[url]
but %[scheme]
does not exist.
Is there a variable or function which can return http
or https
so I do not have to repeat the rule twice? Maybe by somehow setting a variable containing the scheme or maybe by using the value of %[ssl_fc]
which is 0 or 1?
You can do this using
http-request set-var
and%[var(name)]
:As an addition:
If the request schema is needed in the response,
txn
scope must be used instead ofreq
.For example: