Forum Discussion

mbohre_59527's avatar
mbohre_59527
Icon for Nimbostratus rankNimbostratus
Jun 01, 2010

Forward HTTP request to different pools based on URI

I need help in creating a iRule that will forward the user request to appropriate pool based on URI.

 

 

For example, we have three sites www.xyz.com, www.abc.com, and www.test.com . All three sites resolves to VIP 10.10.10.10.

 

 

I need help in creating a iRule ( bind to VIP 10.10.10.10) to forward request for www.xyz.com to POOL1, www.abc.com to POOL2, and www.test.com to POOL3.

 

 

Thanks,

 

Mike

 

 

 

 

 

 

  • This will do it for the [HTTP::uri]:

    
    when HTTP_REQUEST {
       switch -glob [string tolower[HTTP::uri]] {
         "/content1*" { pool pool.for.content1 }
         "/content2*" { pool pool.for.content2 }
         "/content3*" { pool pool.for.content3 }
         default  { HTTP::redirect http://[getfield [HTTP::host] ":" 1]/content1 }
       }
    }
    

    It looks like your might want to do it for the [HTTP::host] though.

    Example: http://www.website.com/subcontent/index.html

    [HTTP::host] = www.website.com

    [HTTP::uri] = /subcontent/index.html
  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    You could also use HTTP classes for this in 9.4.0+ and avoid an iRule. Create one HTTP class per pool, customise the Host header filter to look "www.xyz.com", select the action of "send to pool" and set the corresponding pool. For default pool selection, you can add a final HTTP class with no filters enabled which selects the "default" pool. Then add the HTTP classes to the virtual server under the Resources tab.

     

     

    Aaron
  • Hey guys, I'm trying to do something very similar. I saw your iRule example, tried it, but I'm getting a sysntax error:

     

    line 2: [wrong args] [string tolower[HTTP::uri]]

     

     

    Here's my rule:

     

     

    when HTTP_REQUEST {

     

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

     

    "/start*" { pool zero-new_http-pool }

     

    "/*" { pool zero_http-pool }

     

    }

     

    }

     

     

    Any ideas?

     

     

    Thanks!
  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    Hi Chris,

    Can you try putting a space between [string tolower and [HTTP::uri]]? You can also change /* to the default keyword.

    
    when HTTP_REQUEST {
       switch -glob [string tolower [HTTP::uri]] {
          "/start*" { pool zero-new_http-pool }
          default { pool zero_http-pool }
       }
    }
    

    Aaron