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 contains "hr") {
redirect to "https://pshr.txxx.com/hr"
}
else if (http_uri contains "SELFSERVICE" or http_uri contains "selfservice") {
redirect to "https://pshr.txxx.com/selfservice"
}
else if (http_uri contains "FINTI" or http_uri contains "finti") {
redirect to "https://psfin.txxx.com/finti"
}
else if (http_uri contains "FINTL" or http_uri contains "fintl") {
redirect to "https://psfin.txxx.com/fintl"
}
else if (http_uri contains "FINSPC" or http_uri contains "finspc") {
redirect to "https://psfin.txxx.com/finspc"
}
else {
discard
}
2 Replies
- unRuleY_95363Historic F5 AccountBrian,
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. - Brian_Gupta_115
Nimbostratus
Your examples where very helpful... My final rule:
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"
} elseif { $my_uri contains "finti" } {
redirect to "https://psfin.txxx.com/finti"
} elseif { $my_uri contains "fintl" } {
redirect to "https://psfin.txxx.com/fintl"
} elseif { $my_uri contains "finspc" } {
redirect to "https://psfin.txxx.com/finspc"
}
}
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