Forum Discussion
kco
Altostratus
Apr 01, 2009question about matchclass and "contains"
I would like to use matchclaass function with the "contains" operator. We want to shunt requests from Googlebot User-Agent to a separate pool of servers. I've searched DevCentral and found ma...
spark_86682
Apr 02, 2009Historic F5 Account
It's not that either form is right or wrong, it's that they do different things, and you should use the form that does the thing you want.
The iRules Wiki entry on this seems to explain the difference pretty clearly, but I'll use the "Controlling Bots" iRule as another example (http://devcentral.f5.com/wiki/default.aspx/iRules/ControllingBots.html).
That iRule has a list of User-Agents in a class (called "bots") and an iRule that looks like:
when HTTP_REQUEST {
if { [matchclass [string tolower [HTTP::header User-Agent]] contains $::bots] } {
pool slow_webbot_pool
} else {
pool default_pool
}
}
This uses the "matchclass " form, which sees if the value contains any of the items in the data group. For example, one item in the data group is "googlebot", so if the User-Agent string was "googlebot", "I am a googlebot", "googlebot 2000", or "This is googlebot v1.2.3", then it would match. If the User-Agent string was just "bot", it would not match (because ["bot" contains "googlebot"] returns false).
If the rule used the other form ("matchclass "), then the comparison would go in the other direction. So, if the User-Agent string was "googlebot", or "google", or "bot", then it would match (because ["googlebot" contains "bot"] returns true), but if it was "I am a googlebot", "googlebot 2000", or "This is googlebot v1.2.3", it would not match (because ["googlebot" contains "googlebot 2000"] returns false).
Make sense?
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
