Forum Discussion
Pool Selection Based on URI and URL Modification
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:
- https://test.test.com/url1 to pool1 then remove /url1
- https://test.test.com/url2 to pool2 then remove /url2
- https://test.test.com/url3 to pool3 then remove /url3
- https://test.test.com/url4 to pool4 then remove /url4
- https://test.test.com/ to pool5
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!!
- Stanislas_Piro2Cumulonimbus
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 } }
- Stanislas_Piro2Cumulonimbus
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 } }
- TechitectNimbostratus
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!
- mimlo_61970Cumulonimbus
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.
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