Forum Discussion
Brian_Kenworthy
Nimbostratus
Oct 03, 2006Inspect URI without Case Senstivity?
Hello all,
I have created the following rule to redirect traffic based on the URI to another pool, however, I want the rule to ignore case sensitvity within the URI string. Here is my rule:
when HTTP_REQUEST {
set uri [HTTP::uri]
if { $uri matches_regex "/_xml/ORS/status.asp*" }{
pool mypool_B2B_SSL
} else {
pool mypool.com_SSL
}
}
If I browse using the exact snytax, everything works fine, but it I use a lower case "ors", it fails i.e. https://mydomain/_xml/ors/status.asp I want the rule to fire on any case change that a user puts into the string.
Thanks in advance for the help.
Brian
3 Replies
- matches_regex is way overkill for a simple string comparison. Regular expressions are very CPU intensive so it's better to not use them if you don't have to.
As for the case sensitivity, you can use the TCL "string tolower" command in your comparison. I'd go with something like this:when HTTP_REQUEST { if { [string tolower [HTTP::uri]] starts_with "/_xml/ors/status.asp" }{ pool mypool_B2B_SSL } else { pool mypool.com_SSL } }
Hope this helps...
-Joe - Brian_Kenworthy
Nimbostratus
Thanks Joe, that did the trick!!
One last question...I have a handful of paths to compare, so I added them to my rule with the "or" clause:
when HTTP_REQUEST {
if { [string tolower [HTTP::uri]] starts_with "/_xml/ors/status.asp"
or [string tolower [HTTP::uri]] starts_with "/_xml/vendor/status.asp"
or [string tolower [HTTP::uri]] starts_with "/_xml/client/status.asp" }{
pool mypool_B2B_SSL
} else {
pool mypool.com_SSL
}
Is there any better way to write this rule to avoid redundancy? Thanks again. - I prefer the switch statement myself (or a data group in combination with the matchclass command if you have a lot more strings to match.
Here's how the switch statement would look:when HTTP_REQUEST { switch -glob [string tolower [HTTP::uri]] { "/_xml/ors/status.asp*" - "/_xml/vendor/status.asp*" - "_xml/client/status.asp*" { POOL mypool_B2B_SSL } default { pool mypool.com_SSL } } }
The -glob makes the switch perform like unix file globbing (wildcarding). This is much less expensive CPU-wise than a regular expresion check and gives you the flexibility to use wildcards in your comparisons. Note that I put a "*" at the end of the strings making it equivalent to a "starts_with" comparison.
-Joe
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects