Forum Discussion

daemien_139983's avatar
daemien_139983
Icon for Nimbostratus rankNimbostratus
Jun 13, 2014
Solved

irule redirect and switch -glob

Hey guys - trying to setup irule so we can redriect uri to servers.

 

how can i add the switch -glob in to this irules - or is there a better way of d0ing this?

 

Code when HTTP_REQUEST { 
if { [HTTP::uri] == "/filetransfer" } {
    pool mix_prod_v1_filetransfer
}
    elseif { [HTTP::uri] == "/view.net" } {
    pool mix_prod_v1_view
}
    elseif { [HTTP::uri] == "/webimagedownloader/" } {
    pool mix_prod_v1_webimage
}
else {
    pool mix2prod.test_pool
} 

}

 

  • I gather you are trying to use partial matching with the -glob option. Try this...

    when HTTP_REQUEST {
      switch -glob [string tolower [HTTP::uri]] {
        "/filetransfer*" { pool "mix_prod_v1_filetransfer" }
        "*/view.net" { pool "mix_prod_v1_view" }
        "*/webimagedownloader/*" { pool "mix_prod_v1_webimage" }
        default { pool "mix2prod.test_pool" }
      }
    }
    

    I've included all three type of pattern matching. Adjust as needed.

    item* -- starts with item
    *item -- ends with item
    *item* -- contains item
    

6 Replies

  • Hi Daemien, Try the following

       when HTTP_REQUEST {
            switch -glob [string tolower [HTTP::uri]] {
              "/filetransfer" { 
                    pool mix_prod_v1_filetransfer 
              }
              "/view.net" { 
                    pool mix_prod_v1_view 
              }
              "/webimagedownloader/" {
                    pool mix_prod_v1_webimage
              }
              default { 
                    pool mix2prod.test_pool 
              }
             }
        }
    

    I hope this helps

    -=Bhattman=-

  • I gather you are trying to use partial matching with the -glob option. Try this...

    when HTTP_REQUEST {
      switch -glob [string tolower [HTTP::uri]] {
        "/filetransfer*" { pool "mix_prod_v1_filetransfer" }
        "*/view.net" { pool "mix_prod_v1_view" }
        "*/webimagedownloader/*" { pool "mix_prod_v1_webimage" }
        default { pool "mix2prod.test_pool" }
      }
    }
    

    I've included all three type of pattern matching. Adjust as needed.

    item* -- starts with item
    *item -- ends with item
    *item* -- contains item
    
    • The_Bhattman_16's avatar
      The_Bhattman_16
      Icon for Nimbostratus rankNimbostratus
      Remember "-glob" switch allows the use of starts_with, ends_with, and contains. -=Bhattman=-
  • You can't do /Filetransfer or Filetransfer/ or Filetransfer. without the "-glob" statement in the switch command.

     

    The following is great article about IF, ELSEIF, and Switch functions

     

    https://devcentral.f5.com/articles/irules-optimization-101-01-if-elseif-and-switch

     

    -=Bhattman=-

     

  • If any of the above posts have provided a solution to your issue, please indicate so by clicking the tick to the left of them. This gives feedback and recognition to the volunteers who responded to your issue