Forum Discussion
Cody_Conklin_17
Nimbostratus
Aug 11, 2005iRule variable match is case sensitive
I have an iRule that behaves normally:
if (http_uri starts_with "/authentication") {
use pool IIS_Pool_80
}
else if (http_uri starts_with "/certapp") {
use pool IIS_Pool_80
}
else if (http_uri starts_with "/lms") {
use pool IIS_Pool_80
}
else {
use pool beta.xyz.com
}
Unfortunately, it does not work if a user accidentally goes to the URI "/Authentication". How do a make the variable match be case insensitive? Regardless of whether a user types "/Authentication" or "/authentication", it should direct to IIS_Pool_80.
14 Replies
- Colin_Walker_12Historic F5 AccountCody,
Which release of the 4.x code are you on? There are a couple different ways of doing this as I described here:
Click here http://devcentral.f5.com/default.aspx?tabid=28&forumid=16&postid=3715&view=topic
-Colin - Cody_Conklin_17
Nimbostratus
BIG-IP Kernel 4.5.12 Build19-a - Cody_Conklin_17
Nimbostratus
hmmm....I didn't really like the way that iRule was written, so I decided to consolidate it down to a single "if" statement, as follows:
if (http_uri starts_with "/authentication" or "/certapp" or "/lms") {
use pool IIS_Pool_80
}
else {
use pool beta.xyz.com
}
Since I've made that change, the variable match is now CaSe InSeNsItIvE. Anyone care to let me know why?
Regardless, it's behaving perfectly. Thanks for the help. - Colin_Walker_12Historic F5 AccountCody,
There was a similar post to this yesterday. Check it out here, Click here
This shows the tolower command which should accomplish what you're looking for. It was implemented in the 4.6.1 release, which means it should be incorporated into your current 4.5.12 release as well.
Let me know if you have any problems.
-Colin - Are you sure it is case insensitive or is it just allowing everything in. I'll have to check with the iRules 4.x implementation of starts_with but I believe that the logical "or" operators are not working the way you think.
I believe that your rule is equating to:if ( (http_uri starts_with "/authentication") or ("/certapp") or ("/lms") ) { use pool IIS_Pool_80 } else { use pool beta.xyz.com }
And that theor ("/certapp")
is always evaluating to true.
Have you verified that uri's without your strings are falling through to the beta.xyz.com pool?
If it is really working, then that's an extension of the "starts_with" operator that I haven't seen before and didn't know existed.
-Joe - Cody_Conklin_17
Nimbostratus
You're absolutely right Joe. All conditions are now matching, so nothing is using the "else" pool.
I've tried implementing the "tolower" function, as described by Colin, but I'm getting a syntax error on the keyword tolower:
if (tolower (http_uri starts_with "/authentication")) {
use pool IIS_Pool_80
}
else {
use pool beta.pmi.org
}
Error 331835 -- Rule string to tree failed. - syntax error at 'tolower'
line 1: if (tolower http_uri starts_with "/authentication") { - Martin_MachacekHistoric F5 AccountThe "tolower" function converts a string to lowercase, it does not make string match case insensitive.
Correct syntax is:if (tolower(http_uri) starts_with "/authentication") { use pool IIS_Pool_80 } else { use pool beta.pmi.org }
BTW, the best way how to match one of several strings is to use a class and the "one of" operator. It is more efficient than several string match experssions ORed and also more efficient than a chain of if-else statements. One of your previous rule examples could be rewritten like this:class allowed_uris { "/certapp" "/authentication" "/lms" } rule r1 { if(tolower(http_uri) starts_with one of allowed_uris) { use pool IIS_Pool_80 } else { use pool beta.pmi.org } } - Colin_Walker_12Historic F5 AccountCody,
I have to apologize for my previous post about tolower. This applies in version 4.6.1 and after.
In the 4.5.x branch, ther are only two real ways to work around the case sensitivity issue. One is with a regular expression. While this option works, it's more resource intensive.
The other option is to create a class, like mmac mentioned, and use the one of functionality, but this doesn't scale well unless you know which characters might be capitalized.
Thanks,
-Colin - Mark_Porter_979
Nimbostratus
Hi Colin,
Can you post an example of how to use a regex to work around the case sensitivity issue? I'm using 4.5.12, and have exactly the same problem.
Thanks! - Christopher_Ach
Nimbostratus
Hi
I want to use this piece of code above
class allowed_uris {
"/certapp"
"/authentication"
"/lms"
}
rule r1 {
if(tolower(http_uri) starts_with one of allowed_uris) {
use pool IIS_Pool_80
} else {
use pool beta.pmi.org
}
}
but im wondering if I need to have a WHEN statement above it that says
when HTTP_REQUEST {
}
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
