Forum Discussion
iRule - Direct traffic to specific pools based on host and URI
Good Afternoon,
I am struggling to find a winning combination for the following process.
The default Virtual Server pool is different and required for all other sites.
Step 1 - The website www.communigator.co.uk to use Pool_Website
Step 2 - Any website with the /LZ/ in the URi to us Pool_Landing_64
Step 3 - The web site www.communigator.co.uk with URI /login to use Pool_Admnin_64
I can get the site to hit the pool in step 1 but I get mixed response from when I try and add step 2 and 3.
Here is the syntax so far.
when HTTP_REQUEST { if {[HTTP::uri] starts_with "/login"} { pool Pool_Admin_64 }
if {[HTTP::uri] starts_with "/lz/*"} {
pool Pool_Landing_64 }
if { [HTTP::host] eq "www.communigator.co.uk"} {
pool Pool_Website }
}
Regards, Stuart
10 Replies
- El_Jefe
Nimbostratus
when HTTP_REQUEST { if { [HTTP::path] starts_with "/lz/" }{ pool Pool_Landing_64 } elseif { [HTTP::path] starts_with "/login/" }{ pool Pool_Admin_64 } else { pool Pool_Website } }
- El_Jefe_43496
Nimbostratus
when HTTP_REQUEST { if { [HTTP::path] starts_with "/lz/" }{ pool Pool_Landing_64 } elseif { [HTTP::path] starts_with "/login/" }{ pool Pool_Admin_64 } else { pool Pool_Website } }
- shaggy
Nimbostratus
throw some tolower's in there, too: ... if { [string tolower [HTTP::path]] starts_with "/lz/" }{ pool Pool_Landing_64 } elseif {[string tolower [HTTP::path]] starts_with "/login/" }{ pool Pool_Admin_64 ... - El_Jefe_43496
Nimbostratus
windowdressing. screen doors on submarines.
- Brent_West_7733Historic F5 Account
Maybe something like this would help?
when HTTP_REQUEST { set debug 1 set client_info "[IP::client_addr]:[TCP::remote_port]: [HTTP::host][HTTP::uri]" if { $debug } { log local0. "$client_info requests [HTTP::host] and [HTTP::uri]" } if { [string tolower [HTTP::uri]] starts_with "/login" } { if { $debug } { log local0. "$client_info - line 9 selected - pool is Pool_Admin_64" } pool Pool_Admin_64 } elseif { [string tolower [HTTP::uri]] starts_with "/lz/" } { if { $debug } { log local0. "$client_info - line 14 selected - pool is Pool_Landing_64" } pool Pool_Landing_64 } elseif { [getfield [string tolower [HTTP::host]] ":" 1] eq "www.communigator.co.uk"} { if { $debug } { log local0. "$client_info - line 19 selected - pool is Pool_Website" } pool Pool_Website } else { if { $debug } { log local0. "$client_info - line 24 selected - No Match, using default" } }}- Brent_West_7733Historic F5 AccountThe [HTTP::host] can look like www.example.com:80 which is why we need the getfield, and we would like our test to be case insensitive, hence the string tolower. The [HTTP::uri] should be case insensitive, and I removed your wildcard, because string matches don't work that way. starts_with is sufficient. I added 'elseif' because you usually want the iRule to stop processing conditionals after a pool selection is made, but in cases where there are multiple possible matches (a host and a uri) plan your logic accordingly. The last 'pool' statement wins. After you get your iRule situated, remove the debugging statements unless you want them
- Jangle-Man_1290
Nimbostratus
Good Morning Brent West,
Thank you for your prompt reply and comments I will review and come back to you shortly.
Regards, Stuart
- Jangle-Man_1290
Nimbostratus
Thank you Brent, it has provided 99% of my requirement however when it turns out I need to change "/lz/" so I can wildcard anything before for example "*lz/" but that seems to fail any ideas?
Regards, Stuart
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