Forum Discussion
pwallace_110041
Nimbostratus
Jan 25, 2006Double check of rule to get rid of regex.
I am in need of a rule review. I am trying to come up with an alternative to the rule below with matches_regex in it. I need it to have the same end result but I am trying to avoid using the regex due to the cpu hit this can have.
if (http_uri matches_regex "^/locmap/*/*asp") {
use pool mappool
}
else {
discard
}
=====================================================
Below is the rule that I was working on to replace the regex rule. May I please get some feed back on the rule below to see if this will work and give the same results as the regex rule above. Thank you ~ Pippin
class map_uri {
"maplocation.asp"
"maplocation2.asp"
"maplocations.asp"
"movelocation.asp"
"palm.asp"
"printrouteresults.asp"
"routeresult.asp"
}
if (http_uri starts_with '/locmap' and http_uri contains one of map_uri) {
use pool mappool
}
else {
discard
}
3 Replies
- Martin_MachacekHistoric F5 AccountPippin,
your original regular expression is little bit weird, so I first need clarification what it was supposed to match:^/locmap/*/*asp
matches strings that start with "/locmap" followed by zero or more forward slahes (/) and contain "asp" anywhere after the sequence of forward slashes. So, for example:/locmap////////gasping
matches, but:/locmap/mapdir/mymap.asp
does not because the regex does not allow any intervening characters between the forward slashes.
I'm assuming (based on your re-factored rule) that you actually wanted:^/locmap/.*/.*[.]asp
If this is the case, then your suggested rules is correct, assuming that you want to also match URIs like this:/locmapperwidget/crazymaplocations.asp_and_whatever_here
If you only want to match URIs that start with "/locmap/" and end with name of one of your ASPs, then your rule needs to look like this:if (http_uri starts_with "/locmap/" and http_uri ends_with one of map_uri)
NOTE: the URI would not match, if it contains any variables "?var=value". - pwallace_110041
Nimbostratus
Why would the following be true?
NOTE: the URI would not match, if it contains any variables "?var=value".
Also would "http_uri ends_with one of map_uri" be case sensitive or do I need to do something like the "to lower" command?
The uri's will contain caps as seen below.
http:\\map.now.com\locmap\\MapLocation.asp
http:\\map.now.com\locmap\\MapLocation2.asp
http:\\map.now.com\locmap\\MapLocations.asp
http:\\map.now.com\locmap\\MoveLocation.asp
http:\\map.now.com\locmap\\Palm.asp
http:\\map.now.com\locmap\\RouteResult.asp
http:\\map.now.com\locmap\\PrintRouteResults.asp - Martin_MachacekHistoric F5 AccountAnswer 1 (Why would the following be true?):
Because of the "http_uri ends_with one of map_uri" condition in the suggested rule.
Answer 2: (are http_uri matches case sensitive?)
Yes, all string matches in iRules are case sensitive. You'd need to use the "tolower" function to convert the URI to all lowercase and compare it to all lowercase string if capitalization in your URIs may vary and you want to match all alternatives. The condition in your rule may look like this:http_uri starts_with "/locmap/" and tolower(http_uri) ends_with one of map_uri
and the map_uri class would need to contain only lowercase versions of the map related URIs.
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