redirect to two pools with diff ports

I’m pretty new to irule. I’m trying to access two different web instances using URIs. Requirement is to use single VIP. e.g.,

http://www.mycompany.com/ ;goes to pool1:port1

http://www.mycompany.com/app2 ;goes to pool2:port2 with no app2 in url

Both web instances are on same server(s) listening on two different TCP ports and have their own index.html. I have created pool1 and pool2 with following irule:

when HTTP_REQUEST {

if [string tolower [HTTP::path]] eq “/app2”}{

pool Pool_2

}else {

pool Pool_1

}

}

The problem is that I can only get to pool2 by using a file called “app2” in the 2nd web instance folder and “app2” word is visible. I have also tried: HTTP::redirect “http://[HTTP::host]/” after pool pool_2 but that goes to pool1.

How do I get F5 to send it to /index.html for second web instance for http://www.mycompany.com/app2 request and remove “app2” from the URL?

Any help is appreciated very much. Thanks.

Hi AFara2000,

You could change the URI in the following manner

when HTTP_REQUEST { 
    switch [string tolower [HTTP::uri]] { 
      "/app2" { 
                  HTTP::uri /[HTTP::uri] 
                  pool Pool_2 
                  } 
      default { 
                  pool Pool_1 
                 } 
     } 
 }

I used the switch command because in the long run it executes faster then IF-ELSE.

I hope this helps

Bhattman

Thanks Bhattman for your code but that didn’t take care of /app2 in uri. I decided to use /app2/* for all web application 2 paths. Therefore, I modified your code and this seems to be working fine:

when HTTP_REQUEST {

-glob: allow string pattern matching to check within requested path

switch -glob [string tolower [HTTP::path]] {

“/app2” {

log local0. “Exact macth for /app2 - sending to pool_2 in [HTTP::uri]”

HTTP::uri [HTTP::uri]/

pool Pool_2

}

“/app2/*” {

log local0. “Matched /app2/* - No rewrite, sending to pool_2 for [HTTP::uri]”

pool Pool_2

}

default {

log local0. “No match for app2, sending to default pool_1 for [HTTP::uri]”

pool Pool_1

}

}

}

My next step is to expand this code to use https instead of http. Can this code still be used? I will be planning to terminate SSL using clientside and serverside SSL certs. Any hint or help would be highly appreciated. Thanks,

Al