Forum Discussion

Adrian_P's avatar
Adrian_P
Icon for Nimbostratus rankNimbostratus
Aug 21, 2013

Add a prefix before sending the request to the Pool

Hi,

 

Scenario :

 

A single VS (3.3.3.3) with two different Pool based on the URI prefix :

 

Pool A: the member web server 1.1.1.1 is configured on a Virtual Directory /web

 

Pool B: the member web server 2.2.2.2 is configured on a Virtual Directory /reports

 

Requirement:

 

Client browser must connect to the root directory of the Virtual Server and the LTM will use Pool A and add the /web prefix before sending the request to the Pool except /reports which the LTM will use Pool B and pass through the URI with no changes

 

Example:

 

  • http://3.3.3.3/ <==> use Pool A <===> http://1.1.1.1/web
  • http://3.3.3.3/image <==> use Pool A <===> http://1.1.1.1/web/image
  • http://3.3.3.3/reports <==> use Pool B <===> http://2.2.2.2/reports
  • http://3.3.3.3/reports/pdf <==> use Pool B <===> http://2.2.2.2/reports/pdf

Can someone kindly enough to build the irules that meet the requirement above ?

 

Many thanks in advance.

 

Adrian.

 

5 Replies

  • Hi Scott, I typed my questions in the text editor and use markdown format. I am using Chrome Browser Version 28.0.1500.95
  • when HTTP_REQUEST {
    if {[HTTP::uri] starts_with "/reports"}{
    pool pool_b
    } else {
    HTTP::uri /web[HTTP::uri]
    pool pool_a
    }
    }
    

    OR

    when HTTP_REQUEST {
    if {[string tolower [HTTP::uri]] starts_with "/reports"}{
    pool pool_b
    } else {
    HTTP::uri /web[HTTP::uri]
    pool pool_a
    }
    }
    
  • just in case you have not yet seen this solution.

     

    sol9800: Using an iRule to load balance HTTP requests to multiple pools

     

    http://support.f5.com/kb/en-us/solutions/public/9000/800/sol9800.html

     

  • Thank you very much for all the help.

    I have finally get it working and here is the final irules that I use. I add some log command as a troubleshooting tool to log the variable in the /var/log/ltm

     Add /web prefix 
     Unless it started with /reports
    
    when HTTP_REQUEST {
    
      log local0. "in HTTP_REQUEST"
    
      set orguri [HTTP::uri]
      log local0. "Original: $orguri."  
    
    if {[string tolower $orguri] starts_with "/reports"}
      {
      pool pool_b
      }
    else {
        set newuri "/web[HTTP::uri]"
        HTTP::uri $newuri 
        pool pool_a
        }
    log local0. "After mapping: [HTTP::uri]"
    log local0. "Pool: [LB::server pool]"
    }