Match data in query string, perform redirect

Hello,

I’m new to HAProxy and find the documentation a little confusing for a non-developer. Nonetheless, I’m determined to replace our IIS proxies with HAProxy.

I need to match the pattern “disco” in a query string then redirect to error.html. In IIS, I’d match the entire URL (.*) and then check for “disco” in the query string. If “disco” appeared, I’d redirect to error.html.

With HAProxy, should I be fetching the query-string with “query” and how I would construct the ACL? Any help would be greatly appreciated.

Thanks!

This seems to work (matches string exactly which isn’t ideal):
acl no_discovery query -i disco
http-request redirect location /error.html if no_discovery

This doesn’t seem to work but I’m not sure if I’m organizing my regex correctly:

acl no_discovery query -i /disco.*/
http-request redirect location /error.html if no_discovery

Thoughts on this solution? Seems to work?

acl no_discovery query -i -m reg disco.*
http-request redirect location /error.html if no_discovery

Thanks!

What is it that you would like to accomplish EXACTLY?
Please elaborate with examples what you are trying to match.

query just contains the text after the first question mark:
https://cbonte.github.io/haproxy-dconv/1.7/configuration.html#7.3.6-query

When you just look for a substring, use the substring functionality, no need for regexp:
-m sub disco

You can find examples and functionality in the documentation:
https://cbonte.github.io/haproxy-dconv/1.7/configuration.html#7

Thanks for the reply; my apologies for not being more clear. I’m looking to match anything in the query string (after the “?”) that has “disco” in it (case insensitive) and send the traffic to an error page.

Examples that should be matched:

DISCO, disco, Disco, dISCo, Discovery, discovery, DISCOVERY, etc.

I do not recall the precise reason for this requirement but I believe it had something to do with Google Analytics. I could be way off.

I am not concerned about PATH (before the ?) hence the use of “query”. Since I want to do more than match the simply a string, I figured I had to do a regex?

substring matches search for a substring in the entire string, that should be everything you need.

So that would be:

acl no_discovery query -i -m sub disco
http-request redirect location /error.html if no_discovery
1 Like

Interesting. I guess I didn’t completely understand what it meant when I first read it in the docs. In your opinion, when is it more appropriate to use a substring vs a regexp? (probably a really amateur question I’m sure)

Regardless, thank you very much for your assistance and insight.

If you can use a substring match, then use it. Its simpler, faster and doesn’t need a PCRE library call.

If you need more flexibility that only a regular expression provides, then use it. But for those simple things its not needed.

Sounds good. Thanks again for the help!