Forum Discussion
Robert_Pagano_7
Nimbostratus
Nov 14, 2007pool selection based on path in URI (and subsequent URI path modification)
I am trying to route connections based on the portion of the URI after the hostname.
For example, connections to...
http://www.example.com/lms/path/to/resource
...
Nov 14, 2007
What happens when the URI is "/lms"? The string map will turn it into an empty string which isn't valid for a URI. A URI must be at least a starting slash.
If you wanted to go with a more dynamic approach, this iRule will take the first path element "one" from the URI "/one/two/three", upper case the one to "ONE", create a dynamic pool name "ONE_pool", remove the "/one" from the first URI and then attempt to assign traffic to the dynamic created pool. Note, I used a catch command to catch any errors from assignments to pools that don't exist.
when HTTP_REQUEST {
log local0. "URI: [HTTP::uri]"
set loc [lindex [split [HTTP::uri] "/"] 1]
log local0. "loc: $loc"
if { [string length $loc] > 0 } {
Build the new URI
set new_uri [string map { "/$loc" "" } [HTTP::uri] ]
if { [string length $new_uri] == 0 } {
set new_uri "/"
}
HTTP::uri $new_uri
set new_pool "[string toupper ${loc}]_pool"
if { [catch { pool $new_pool}] } {
log local0. "Error assigning pool to $new_pool"
}
}
}
Of course, if you want to hard code only certain locations, then you could do so like this:
when HTTP_REQUEST {
log local0. "URI: [HTTP::uri]"
switch -glob [HTTP::uri] {
"/lms*" {
set loc "lms"
}
"/content*" {
set loc "content"
}
default {
set loc ""
}
}
log local0. "loc: $loc"
if { [string length $loc] > 0 } {
Build the new URI
set new_uri [string map { "/$loc" "" } [HTTP::uri] ]
if { [string length $new_uri] == 0 } {
set new_uri "/"
}
HTTP::uri $new_uri
set new_pool "[string toupper ${loc}]_pool"
if { [catch { pool $new_pool}] } {
log local0. "Error assigning pool to $new_pool"
}
}
}
Hope this helps...
-Joe
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