Forum Discussion

Rob_76452's avatar
Rob_76452
Icon for Nimbostratus rankNimbostratus
Mar 15, 2010

brand new please help redirect based on uri

My sys admin is saying this is really simple, you should already be done but I'm lost. My first experience with F5's. I think the request is simple if you know about F5 though. anyways..

 

 

I have a pool and I need it to go to /exchange if it is in the url and just go straight through if it is anything else. That is the request but really I believe he needs it to go to /exchange if it is in the url and /owa for everything else.

 

 

I am trying to read/digest the 101 stuff here. Please help if you can.

 

 

Thanks,

 

Rob
  • Hi Rob,

    here is an example of redirect based on URI

     
     when HTTP_REQUEST { 
        if {[HTTP::uri] eq "/blahblah" } { 
           HTTP::redirect "http://www.domain.com/something"  
           } 
     } 
     

    Here are some other examples in the Wiki iRule

    Click here

    Click here

    I hope this helps

    Bhattman

  • Hi Rob,

    I suppose taking the same concept as I explained you can do the following

     
      when HTTP_REQUEST {  
         if {[HTTP::uri] eq "/exchange" } {  
            pool exchange_pool 
         } else { 
            pool other_pool 
         } 
      }  
     

    Or you could right up using the SWITCH command

     
      when HTTP_REQUEST {  
        switch -glob [string tolower[HTTP::uri] { 
            "/exchange" { pool exchange_pool } 
            default {pool other_pool } 
         } 
      } 
     

    I hope this helps

    Bhattman
  • Glad you mentioned the SWITCH command Bhattman, it is perfect for something like this and requires the least amount of overhead to my knowledge.
  • Hey thank you VERY much!!!! I think I got it working. My tests look good enough to pass back to the sysadmin. Here is what I came up with:

     

     

    when HTTP_REQUEST {

     

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

     

    "exchange*" {

     

    log local0. "Matched exchange uri for [HTTP::uri]"

     

    pool tohtca-https

     

    }

     

    "owa*" {

     

    log local0. "Matched owa uri for [HTTP::uri]"

     

    pool tohtca-https

     

    }

     

    default {

     

    log local0.debug "Matched default for [HTTP::uri]"

     

    HTTP::uri "/OWA"

     

    HTTP::uri "[HTTP::uri]OWA"

     

    }

     

     

    }

     

    }

     

     

     

    Thanks again!

     

     

  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    Hi Rob,

    A relative URI should always start with a /, so I'm not sure how that example could be working if you don't have a / or * at the start of the URIs.

    You can combine multiple switch cases that have the same action using syntax like this:

     
     when HTTP_REQUEST { 
        switch -glob [string tolower [HTTP::uri]] { 
           "/exchange*" - 
           "/owa*" { 
              log local0. "Matched exchange or owa uri for [HTTP::uri]" 
              pool tohtca-https 
           } 
           default { 
              log local0.debug "Matched default for [HTTP::uri]" 
              HTTP::uri "/OWA" 
              HTTP::uri "[HTTP::uri]OWA" 
           } 
        } 
     } 
     

    Also, I'd check the default action to make sure that appending the string OWA to the end of any unmatched URI works. I'm not sure what else you have going through the VIP, but I could imagine that append breaking most other requests.

    Aaron