Forum Discussion

sandy16's avatar
sandy16
Icon for Altostratus rankAltostratus
Oct 06, 2014

irule for URI based redirection to separate Pools

Hi, I am new to irules. Need help in writing an irule that does a simple URI re-direction to seperate Pools with NO default Pool on the VS and the F5 returns a default-http page guiding to the user to use the exact uri/wsdl page. Something like - /dev goes to Pool-dev /ct goes to Pool-ct /uat goes to Pool-uat and the response for the default-URL (without any uri) is returned by the F5 saying "for dev use /dev?wsdl and so on...."

 

Please advise?

 

4 Replies

  • Just to add, i am running 11.5.1 HF3 on the 5250v platform.
  • Maybe you can do like that:

        when HTTP_REQUEST {
          set path [string tolower [lindex [split [HTTP::path] "/"] 1]]
          switch -glob $path {
            "dev" { pool pool-dev }
            "ct" { pool pool-ct }
            "uat" { pool pool-uat }
            default {
                HTTP::respond 200 content "Content-Type "text/html" Connection Close"
            }
          }
        }
    

    You can get an iFile or base64 variable content to present the html too. Find some examples in this channel.

    Regards.

  • thanks, can you please shed some light on this irule? what does set path, string tolower, lindex, split, switch -glob variables do?

     

  • You can find a good documentation of iRule events tips and tricks in this link: https://devcentral.f5.com/articles/irules-101-04-switch

    I will try to be clear, here we go:

     This event triggers in http request
    when HTTP_REQUEST {
         this will store the first http path segment in lower case
         so, we'll define the request traffic direction as needed
         example:
         request for url: http://mywebservice.com/DEV/service
         [HTTP::host] ==> mywebservice.com (not used, just to understand)
         [HTTP::path] ==> /DEV/service
         [split [HTTP::path] "/"] ==> [split /DEV/service "/"] ==> { DEV service}
         [lindex { DEV service} 1] ==> DEV
         [string tolower {DEV}] ==> dev (this is useful when web service is case insensitive (windows eg))
         set path ==> stores the value "dev"
        set path [string tolower [lindex [split [HTTP::path] "/"] 1]]
    
    
         this will verify the value stored in path variable
        switch -glob $path {
             case value is "dev", request goes to the pool-dev
            "dev" { pool pool-dev }
    
             case value is "ct", request goes to the pool-ct
            "ct" { pool pool-ct }
    
             case value is "uat", request goes to the pool-uat
            "uat" { pool pool-uat }
    
             otherwise, show the help page
            default {
                 here we will write the response content page
                HTTP::respond 200 content "`Available resource options````