Forum Discussion

Darren_21048's avatar
Darren_21048
Icon for Nimbostratus rankNimbostratus
Jul 10, 2009

URI Pool Redirect Question

Hi everyone,

 

Complete newbie here. I want to create an iRule that redirects to another pool based on the URI. So if I get a request for www.domain.com/xyz/, the request goes to the pool configured for that address, but if the request is for www.domain.com/abc/, the request redirects to another pool.

 

From reading this forum, it looks like it's as simple as the code below but am I missing something? Any help much appreciated. Thanks.

 

 

when HTTP_REQUEST {

 

if { [HTTP::uri] starts_with "/abc" } {

 

pool abc_pool

 

}

 

}

 

  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    That looks good. You should either add a OneConnect profile (Click here) to the virtual server or put an else statement in the iRule. Either option would ensure subsequent requests on the same TCP connection are sent to the correct pool based on the iRule logic.

     

     

    Aaron
  • Hi Aaron,

     

    Thanks for the quick response and information. I've had a read about OneConnect and we have fairly specific logging requirements at present, I think I'll look at that in more detail in future. I'd like to add the 'Else' statement as you suggest but the web farm I run is not small and we run around 400 domains split accross multiple pools. So www.domain1.com points at pool1 and and www.domain2.com points at pool2 etc. Can I word the 'Else' statement to pass the request to the original pool rather than a specific pool if the condition is not met?
  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    You can get the VS's default pool using LB::server in CLIENT_ACCEPTED, so this should suit your needs:

     
     when CLIENT_ACCEPTED { 
      
         Save the default pool name 
        set default_pool [LB::server] 
     } 
     when HTTP_REQUEST { 
        if { [HTTP::uri] starts_with "/abc" } { 
           pool abc_pool 
        } else { 
           pool $default_pool 
        } 
     } 
     

    You can specify a source netmask on a OneConnect profile of 255.255.255.255 to ensure only the same client IP address reuses a server side TCP connection.

    Aaron
  • That works fine though I've modified it slightly as I wasn't dealing with case.

     
     when CLIENT_ACCEPTED {  
      Save the default pool name  
     set default_pool [LB::server]  
     }  
     when HTTP_REQUEST {  
     if {[string tolower [HTTP::uri]} starts_with "/abc" } {  
     pool abc_pool  
     } else {  
     pool $default_pool  
     }  
     }  
     

    I'm looking into this now but I have some URL's with /abcd and /abcd.aspx for example that I do not want to redirect, I only want to redirect /abc or /abc/. If someone has a quick answer, please feel free to post. Thanks.
  • Will this do the trick?

     
     when CLIENT_ACCEPTED { 
      
      Save the default pool name 
     set default_pool [LB::server] 
     } 
     when HTTP_REQUEST { 
     if {[string tolower [URI::path [HTTP::uri] 1 1] equals "/abc" } { 
     pool abc_pool 
     } else { 
     pool $default_pool 
     } 
     }