For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

Parveez_70209's avatar
Parveez_70209
Icon for Nimbostratus rankNimbostratus
Jul 31, 2014

Use of switch -glob statement to switch the traffic in place of if or elseif statement in Irule

Hi Sir,

 

Wanted to make efficient use of switch -glob statement to switch the traffic in place of if or elseif statement: Kindly guide how the Irule looks like.

 

when HTTP_REQUEST { log local0. "Uri is [HTTP::uri]" if { [HTTP::uri] equals "/" } { HTTP::redirect "http://[HTTP::host]/SEUILibrary/controller/Lenovo:Enter" log local0. "redirecting to http://www.lenovo.com/us/en" return } elseif {[HTTP::uri] eq "/console"} { HTTP::redirect "http://canadauat.leni2.com" return } elseif {[HTTP::uri] contains "/login.workflow:Enter"} { HTTP::redirect "http://canadauat.leni2.com" return } elseif {[HTTP::uri] contains ":SiteStatus"} { HTTP::redirect "http://canadauat.leni2.com" return } elseif {[HTTP::uri] contains "/seapibroker"} { HTTP::redirect "http://canadauat.leni2.com" return } elseif {[HTTP::uri] contains "/Author"} { HTTP::redirect "http://canadauat.leni2.com" return } }

 

Kindly guide.

 

Regards

 

3 Replies

  • Here is a starting point. I removed the "return"s, so you will have to put them back.

     

    when HTTP_REQUEST { switch -glob [HTTP::uri] { "/" { HTTP::redirect "http://[HTTP::host]/SEUILibrary/controller/Lenovo:Enter" log local0. "redirecting to http://www.lenovo.com/us/en" return } "/console" { HTTP::redirect "http://canadauat.leni2.com" } "/login.workflow:Enter" { HTTP::redirect "http://canadauat.leni2.com" } ":SiteStatus" { HTTP::redirect "http://canadauat.leni2.com" } "/seapibroker" { HTTP::redirect "http://canadauat.leni2.com" } "/Author" { HTTP::redirect "http://canadauat.leni2.com" } default { HTTP::redirect "http://somewhere.anywhere.com/last/resort.aspx" } } }

     

    If this is a website that you are concerned about search-engine rankings, you may consider using 301 redirects: HTTP::respond 301 Location "http://somewhere.anywhere.com/last/resort.aspx" Also if you did - switch -glob [string tolower [HTTP::uri]], then if somebody did not type in the case correctly, it would still work (of course, you would have to make all of your match-cases lower case. Hope this helps.

     

  • sorry I am failing to understand the Irule. Can you put in some good format.

     

  • nathe's avatar
    nathe
    Icon for Cirrocumulus rankCirrocumulus

    I've amended slightly, including string tolower and removing some of the lines. hope this is what you're after.

    when HTTP_REQUEST { 
    switch -glob [string tolower [HTTP::uri]] {
     "/" { 
        HTTP::redirect "http://[HTTP::host]/SEUILibrary/controller/Lenovo:Enter" 
     log local0. "redirecting to http://www.lenovo.com/us/en" 
      }
     "/console" - 
     "*/login.workflow:enter*" -
     "*:sitestatus*" -
     "*/seapibroker*" - 
     "*/author" {
        HTTP::redirect "http://canadauat.leni2.com"
      }
     default { 
        HTTP::redirect "http://somewhere.anywhere.com/last/resort.aspx" 
      } 
     } 
    }
    

    Hope this helps.

    N