Running Haproxy v3.0.11
I have a URL https://santosh.haproxy.com/config
My need is that whenever this URL is called, a query string should be appended so it should look like:
https://santosh.haproxy.com/config**?dept=1&age=2
I tried http-request set-path, however this ignores the query part.
Not sure if I need to use set-uri or set-query, I tried them both without luck. Looks like I am missing something or doing something wrong.
Would be glad for a suggestion to achieve this.
Note: Ignore the “**” in the URL path. It got auto-added and I am unable to remove it.
To set a query you need to use set-query.
If it doesn’t work, provide the config so we can help you.
I tried the below:
http-request set-uri https://santosh.haproxy.com/config?dept=1&age=2 if host_santosh path_config
where
host_santosh is
acl host_santosh hdr(host) -i santosh.haproxy.com
path_config is
acl path_config path -i /config
This somewhat works.
However, this redirects everything regardless of the query I use.
For example, it redirects even
https://santosh.haproxy.com/config?dept=**5**&age=**5 **
to
https://santosh.haproxy.com/config?dept=1&age=2
This is not what I want. I want to explicitly only redirect “https://santosh.haproxy.com/config”
Anything apart from this should not be modified. The same issue is faced even when using set-query.
Please suggest if anything can be done differently to achieve this.
So your actual problem is that your ACL matches too much.
This is because you only want to add the query only when no query exists, however you have no ACLs in place to check for this.
I recommend replacing the path with pathq in the ACL so you are including the query in this check as opposed to checking only the path and using set-query instead of set-uri, because forcing a absolute URI will have impact on the request going to your backend, which you don’t want.
acl host_santosh hdr(host) -i santosh.haproxy.com
acl pathq_config pathq -i /config
http-request set-query "dept=1&age=2" if host_santosh pathq_config
Awesome. This worked. pathq is exactly what I needed.
Thank you so much once again Lukas!!
1 Like