Forum Discussion
Dave_Horsey_225
Nimbostratus
Apr 12, 2006multiple "uri contains" matches
I am trying to write a rule that will catch many different uri matches. The orginal rule that I am working off is as follows:
when HTTP_REQUEST {
set uri [string tolower [HTTP::uri]]
if { $uri contains "blog" } {
pool MIS-WEB21-CS
}
else {
pool MIS-WEB20-4
}
}
I would like to add uri contains "msgs" and "theme" to this rule. So, if the uri contains blog or msgs or theme, it will redirect to pool MIS-WEB21-CS if not then go to pool MIS-WEB20-4. I have tried it a few different ways with no luck.
3 Replies
- Colin_Walker_12Historic F5 AccountWhile you could just put multiple "if" statements in your rule, the most efficient way to do this, especially if you start talking about many different matches, rather than just 3, is to use a class, and the matchclass function.
First, you'd set up a data group, either via the gui, as type "String" or via the cli.
It would look something like this:class myURIs { "blog" "msgs" "theme" }
Then, you'd update your rule to perform a search of the class, and act accordingly, like so:when HTTP_REQUEST { if { [matchclass [string tolower [HTTP::uri] ] contains $::myURIs ] } { pool MIS-WEB21-CS } else { pool MIS-WEB20-4 } }
This way, if the URI matches anything in the myURIs class, the matchclass will return true, and traffic will go to the MIS-WEB21-CS pool.
This also makes it easy to manage which URIs this is true for. Simply add or remove them from the class as needed, and you won't have to update the rule at all.
HTH,
Colin - Dave_Horsey_225
Nimbostratus
I get the following error when I try to save the rule:
01070151:3: Rule [Blog_Redirect] error:
line 2: [undefined procedure: class] [class myURIs { "blog" "msgs" "theme"}]
I am currently running BigIP version 9.0.5. Is class not available in this version?
Here is the entire rule that I am trying to save:
class myURIs { "blog" "msgs" "theme"}
when HTTP_REQUEST {
if { [matchclass [string tolower [HTTP::uri] ] contains $::myURIs ] } {
pool MIS-WEB21-CS
} else {
pool MIS-WEB20-4
}
} - The class is a data group. The "class" string is used sometimes because that is the internal format used in the bigip.conf file. If you go into the iRules section of the GUI, you'll see a tab titled "Data Group List". Create a string data group named "myURIs" with the given items and you should be set.
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