Forum Discussion

Jorge_48257's avatar
Jorge_48257
Icon for Nimbostratus rankNimbostratus
Apr 18, 2011

Simple URI iRule Request

Need some quick help on what I believe to be a simple irule. I'm looking to create an irule that does a simple redirect if the requested site has no uri.

For example:

 

request - https://example.domain.com

 

redirect - https://example.domain.com/example1

 

 

 

I would also like to exclude/ignore one sepicific uri.

 

request - https://example.domain.com/example2 - if URI = example2 then leave it alone.

 

 

 

Thanks!

 

4 Replies

  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    So what you're looking for is something like:

     

     

    
    when HTTP_REQUEST {
      
      switch -glob [string tolower [HTTP::uri] {
        
        "" - 
        
        "/" {
           HTTP::redirect "https://example.domain.com/example1"
      }
    }

     

     

    You could, of course, write this many different ways. You don't need to specifically call out example2 in the URI because the code is only matching empty URIs. /example2 won't be affected.

     

     

     

    Colin
  • Here is what ended up working for me after identifying all the URIs I needed. Looks messy but it works.

     

    when HTTP_REQUEST {

     

    if {[HTTP::uri] contains "/Microsoft-Server-ActiveSync" } {

     

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

     

    } else {

     

    if {[HTTP::uri] contains "/owa" } {

     

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

     

    }else {

     

    if {[HTTP::uri] contains "/ecp" } {

     

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

     

    } else {

     

    if {[HTTP::uri] contains "/Autodiscover" } {

     

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

     

    } else {

     

    if {[HTTP::uri] contains "/EWS" } {

     

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

     

    } else {

     

    if {[HTTP::uri] contains "/Exchange" } {

     

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

     

    } else {

     

    if {[HTTP::uri] contains "/Exchweb" } {

     

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

     

    } else {

     

    if {[HTTP::uri] contains "/OAB" } {

     

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

     

    } else {

     

    if {[HTTP::uri] contains "/Public" } {

     

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

     

    } else {

     

    if {[HTTP::uri] contains "/rpc" } {

     

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

     

    } else {

     

    if {[HTTP::uri] contains "/RpcWithCert" } {

     

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

     

    } else {

     

    HTTP::uri "/owa"

     

    }

     

    }

     

    }

     

    }

     

    }

     

    }

     

    }

     

    }

     

    }

     

    }

     

    }

     

    }
  • just for your information in case u may have not seen it.

     

     

    comparing irule control statements by joe

     

    http://devcentral.f5.com/Tutorials/TechTips/tabid/63/articleType/ArticleView/articleId/1086424/Comparing-iRule-Control-Statements.aspx
  • I think you can clean that up with a switch statement:

    
    when HTTP_REQUEST {
       switch -glob [string tolower [HTTP::path]] {
          "/microsoft-server-activesync*" -
          "/owa*" -
          "/ecp*" -
          "/autodiscover*" -
          "/ews*" -
          "/exchange*" -
          "/exchweb*" -
          "/oab*" -
          "/public*" -
          "/rpc*" {  do nothing for these paths}
          "/rpcwithcert*" {
              Rewrite the URI to /owa
             HTTP::uri "/owa"
          }
       }
    }
    

    Also, you don't need to set HTTP::uri to [HTTP::uri] in your example. You could just leave the clause empty to do nothing.

    Aaron