Forum Discussion
DM_5174
Nimbostratus
Jul 09, 2007<b>Better way to code iRule in 4.5.x code ???</b>
Hi all,
I have version 4.5x code and would like to know if there is any efficient way to
consolidate the code below. I tired to use tolower or class but got an error message. I believe the reason is due to the current 4.5 code does not support
the commands.
Thanks!
if (http_uri contains "site1") {
use pool APACHE_POOL
}
else if (http_uri contains "site2") {
use pool APACHE_POOL
}
else if(http_uri contains "site3") {
use pool APACHE_POOL
}
else if (http_uri contains "site4") {
use pool APACHE_POOL
}
else if (http_uri contains "site5") {
use pool APACHE_POOL
}
else if (http_uri contains "site6") {
use pool APACHE_POOL
}
else if (http_uri contains "site7") {
use pool APACHE_POOL
}
else {
use pool IISWEB-POOL
}
- Deb_Allen_18Historic F5 AccountI think "matches_regex" function would work well here:
if ( tolower(http_uri) matches_regex "(.*)(site1|site2|site3|site4|site5|site6|site7)(.*))" ) { use pool APACHE_POOL } else { use pool IISWEB_POOL }
- Deb_Allen_18Historic F5 AccountI just saw your earlier post, and since it looks like you need to switch just of the beginning of the path, you can simplify just a bit, eliminating the leading wildcard to save the regex engine some work:
if ( tolower(http_uri) matches_regex "(/)(site1|site2|site3|site4|site5|site6|site7)(.*))" ) { use pool APACHE_POOL } else { use pool IISWEB_POOL }
- Deb_Allen_18Historic F5 Account(edited both previous posts to correct syntax. Hopefully I got it right this time -- it's been quite a while since I wrote a v4 iRule...)
- DM_5174
Nimbostratus
Hey deb, - Martin_MachacekHistoric F5 AccountRegular expressions are the least efficient way of matching in
NOTE: the above rule matches also URIs containing the items of the class as substring (e.g. "site666" or "parasite1"). If those matches are not desired, you need to either add delimiting characters to the items in the set (e.g. "/site1/"), use other match operator (e.g. "starts_with", "equals" or "ends_with) or use the substr function to extract the portion of the URI to be matched.class apache_sites { "site1" "site2" "site3" "site4" "site5" "site6" "site7" } rule match_apache_sites { if( http_uri contains one of apache_sites) { use pool APACHE_POOL } else { use pool IISWEB-POOL } }
- DM_5174
Nimbostratus
Unfortunately we are running 4.5.13 so the class function does not work. Please let me know if there are any other way of doing this since upgrading our environment right now is not an option. Eventually we are migrating to the LTMs running v.9x, but right now its to get - Martin_MachacekHistoric F5 AccountI can guarantee you that the rule works on 4.5.13. Classes are part of iRules since version 4.2.
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