Forum Discussion
Brian_Gupta_115
Nimbostratus
Jan 12, 2005Converting a 4.5 rule to an iRule
I have the following 4..5 rule that I need to convert to an irule... Can someone please help me?
Thanks,
Brian
if (http_uri contains "HR" or http_uri con...
unRuleY_95363
Jan 12, 2005Historic F5 Account
Brian,
I would rather you take a stab at this yourself. It's the best way to learn the new syntax. Here are some rules that will make the conversion easier:
a) http_uri is now [HTTP::uri].
b) Tcl syntax requires that you use {} instead of () around the expression in an if statement (ie, instead of "if (...) {...}" you would do "if {...} {...}".
c) You will need to pick an event for the rule to be evaluated under. Since your 4.5 rule is primarily based on the HTTP uri, then the event HTTP_REQUEST would be most suitable.
Here is a basic template with some examples of what you might want to do:
rule my_redirect {
when HTTP_REQUEST {
if { [HTTP::uri] contains "HR" or [HTTP::uri] contains "hr" } {
redirect to "https://pshr.txxx.com/hr"
} elseif { [HTTP::uri] contains "SELFSERVICE" or [HTTP::uri] contains "selfservice") {
redirect to "https://pshr.txxx.com/selfservice"
} more elseif's may following here...
}
}
I also noticed you are often doing a comparison for both upper and lowercase versions of the string. In 9.x, this can be simplified like so:
rule my_redirect {
when HTTP_REQUEST {
set my_uri [string tolower [HTTP::uri]]
if { $my_uri contains "hr" } {
redirect to "https://pshr.txxx.com/hr"
} elseif { $my_uri contains "selfservice") {
redirect to "https://pshr.txxx.com/selfservice"
} more elseif's may following here...
}
}
Good luck, and be sure to post back if you run into any problems.
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
