I’m trying to write an iRule that will redirect traffic to different pools based on URI, as well as altering the URL to remove the URI after the traffic is redirected to the correct pool. I think I have the initial pool redirect figured out, but I can’t figure out how to do that AND THEN shorten the URL. Here are my examples:
This is what I ahve for the pool selection/redirection:
when HTTP_REQUEST {
switch -glob -- [string tolower [HTTP::path]] {
"/url1*" {
pool /Common/Pool1
return
}
"/url2*" {
pool /Common/Pool2
return
}
"/url3*" {
pool /Common/Pool3
return
}
"/url4*" {
pool /Common/Pool4
return
}
"/*" {
pool /Common/Pool5
return
}
}
Thanks all!!
try this:
when HTTP_REQUEST {
switch -glob -- [string tolower [HTTP::path]] {
"/url1*" {
pool /Common/Pool1
HTTP::uri [string map { "/url1" ""} $uri]
return
}
"/url2*" {
pool /Common/Pool2
HTTP::uri [string map { "/url2" ""} $uri]
return
}
"/url3*" {
pool /Common/Pool3
HTTP::uri [string map { "/url3" ""} $uri]
return
}
"/url4*" {
pool /Common/Pool4
HTTP::uri [string map { "/url4" ""} $uri]
return
}
default {
pool /Common/Pool5
return
}
}
same code without html conversion of quote:
when HTTP_REQUEST {
switch -glob -- [string tolower [HTTP::path]] {
"/url1*" {
pool /Common/Pool1
HTTP::uri [string map { "/url1" ""} $uri]
return
}
"/url2*" {
pool /Common/Pool2
HTTP::uri [string map { "/url2" ""} $uri]
return
}
"/url3*" {
pool /Common/Pool3
HTTP::uri [string map { "/url3" ""} $uri]
return
}
"/url4*" {
pool /Common/Pool4
HTTP::uri [string map { "/url4" ""} $uri]
return
}
default {
pool /Common/Pool5
return
}
}
Hi Stanilas,
When I implemented your code additions, I received the following errors on traffic with the specific URI criteria:
Jul 20 15:37:26 F5EXLB01 info tmm2[16571]: Rule /Common/URI_rule : HTTP path for 192.168.100.100 is /url4/XISOAPAdapter/MessageServlet
Jul 20 15:37:26 F5EXLB01 err tmm2[16571]: 01220001:3: TCL error: /Common/URI_rule - can’t read “uri”: no such variable while executing “string map { “/url4” “”} $uri” (“/url4" arm line 3) invoked from within "switch -glob -- [string tolower [HTTP::path]] { "/url4” { pool /Common/Pool_URL4_443 HTTP::uri [string map { “/url4” “”} $uri…"
Thanks!
It looks like $uri is not defined anywhere. I think the intent is to have it set to HTTP::uri, so you can substitute [HTTP::uri] where $uri is.