That works, but for whatever reason causes the config to fail when reloading with the two curly braces together. To avoid that issue, try using two double quotes for the string map instead:
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"
}
}
}