Forum Discussion
Routing based on URI
I need to create an iRule that would send all traffic to the root of website and and about 100 defined subfolders to the default pool. Any undefined subfolders should go to the market pool.
Here is the iRule that I created.
when HTTP_REQUEST timing on {
set uri [string tolower [HTTP::uri]]
switch -glob $uri {
"/*/*" {
switch -glob $uri {
"/uri1/*" - "/uri2/*" - "/url3/*" - "/uri99/*"
{ }
default {
pool market}
}
}
default {
if {!($uri contains ".") && !($uri eq "/")} {
pool market} else {
pool $default_pool}
}
}
}
}
Here is the problem,
test.com/uri1/ goes to the $default_pool
test.com/market1/ goes to the market pool
but if the url is changed back to test.com/uri1/ the request stays in the market pool but it should have gone to the $default_pool instead.
Oneconnect profile resolves the issue with routing but it breaks some other functionality with the application itself so we would rather not use it.
What am I missing from the iRule to make sure that the request goes to the proper pool?
Also, what can I do to optimize the iRule performance? Currently it's averaging about .065ms per request. Do I need to worry about optimizing or is this a decent performance for this iRule?
Thanks!
13 Replies
- Eugene_Reznik_1
Nimbostratus
Thanks nitass but how can I account for all the files in the root like defaut.aspx, aboutus.html , logo.gif, etc? - nitass
Employee
how can I account for all the files in the root like defaut.aspx, aboutus.html , logo.gif, etc?e.g.[root@ve10:Active] config b rule myrule list rule myrule { when HTTP_REQUEST { set uri [string tolower [HTTP::uri]] if { [string last / $uri] == 0 or [class match -- $uri starts_with uri_class] } { pool foo } else { pool qux } } when HTTP_RESPONSE { log local0. "uri: $uri pool: [LB::server pool]" } } [root@ve10:Active] config b class uri_class list class uri_class { { "/uri1/" "/uri2/" "/uri3/" } } [root@ve10:Active] config cat /var/log/ltm Aug 2 22:16:20 local/tmm info tmm[5139]: Rule myrule : uri: /uri1/something pool: foo Aug 2 22:16:30 local/tmm info tmm[5139]: Rule myrule : uri: / pool: foo Aug 2 22:16:33 local/tmm info tmm[5139]: Rule myrule : uri: /index.html pool: foo Aug 2 22:17:16 local/tmm info tmm[5139]: Rule myrule : uri: /sub1/sub2/something pool: qux - Eugene_Reznik_1
Nimbostratus
Wow thanks nitass - simple and elegant!
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* 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