Forum Discussion

Rusty_Tripp_798's avatar
Rusty_Tripp_798
Icon for Nimbostratus rankNimbostratus
Mar 14, 2012

iRule not working properly

Hello,

 

 

I am using the iRule below but when I enter http://site.name/bd, I don't get redirected to http://site.name/bd/folder/...

 

 

Any help would be greatly appreciated.

 

 

Rusty

 

 

when HTTP_REQUEST { if {(([HTTP::uri] equals "/") or ([HTTP::uri] equals "/levi_b2b/init.do"))} { HTTP::uri "/levi_b2b/init.do" } elseif {[HTTP::uri] equals "/bd*"} { HTTP::uri "/bd/public/frameset_top_html.jsp" } else { HTTP::redirect http://leo.levi.com/index.htm } }

7 Replies

  • im not sure you can actually use wildcards in an equals, so in
    {[HTTP::uri] equals "/bd*"}
    , what if you try it with contains or starts with?

    also it seems to forward you to something else then http://site.name/bd/folder/..., but perhaps your script at /bd/public/frameset_top_html.jsp does that?
  • e.g.

     

     

    [root@ve1023:Active] config b virtual bar list

     

    virtual bar {

     

    snat automap

     

    pool foo

     

    destination 172.28.19.79:80

     

    ip protocol 6

     

    rules myrule

     

    profiles {

     

    http {}

     

    tcp {}

     

    }

     

    }

     

    [root@ve1023:Active] config b rule myrule list

     

    rule myrule {

     

    when HTTP_REQUEST {

     

    if {([HTTP::uri] equals "/") or ([HTTP::uri] equals "/levi_b2b/init.do")} {

     

    HTTP::uri "/levi_b2b/init.do"

     

    } elseif {[HTTP::uri] equals "/bd"} {

     

    HTTP::redirect "/bd/public/frameset_top_html.jsp"

     

    } else {

     

    HTTP::redirect "http://leo.levi.com/index.htm"

     

    }

     

    }

     

    }

     

     

    [root@ve1023:Active] config curl -I http://172.28.19.79/bd

     

    HTTP/1.0 302 Found

     

    Location: /bd/public/frameset_top_html.jsp

     

    Server: BigIP

     

    Connection: Keep-Alive

     

    Content-Length: 0

     

     

  • I've actually tried that way as well but ti didn't work. It seems to me that the iRules is being entered multiple times ( I see this using the LOG command ).

     

     

    Here is some information from the log file. All this occured from just one hit ( the first BD is just an indicator to which If statement I took:

     

     

    bd - uri = /bd

     

    bd - uri = /bd/

     

    bd - uri = /bd/public/frameset_top_html.jsp

     

    bd - uri = /bd/frameset_application.sap

     

    bd - uri = /bd/navigation_top.sap

     

    bd - uri = /bd/startEBPP.sap

     

    bd - uri = /bd/navigation.sap

     

     

     

    Here is my latest effort as writing this iRule:

     

    when HTTP_REQUEST {

     

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

     

    "/" { HTTP::uri "/levi_b2b/init.do"}

     

    "/levi_b2b" { HTTP::uri "/levi_b2b/init.do"}

     

    "/docs" { HTTP::uri "/docs/index.html"}

     

    "/bd" { HTTP::uri "/bd/public/frameset_top_html.jsp"}

     

    default { HTTP::redirect "http://leo.levi.com/index.htm" }

     

    }

     

    }
  • can you try to remove the default case?

    e.g.

    when HTTP_REQUEST { 
    switch [string tolower [HTTP::uri]] { 
    "/" { HTTP::uri "/levi_b2b/init.do"} 
    "/levi_b2b" { HTTP::uri "/levi_b2b/init.do"} 
    "/docs" { HTTP::uri "/docs/index.html"} 
    "/bd" { HTTP::uri "/bd/public/frameset_top_html.jsp"} 
    }
    
  • But I still need the switch to take the default so how do I make this happen if it makes the iRule not work?
  • Hi Rusty Tripp,

    You can use Wildcards inside of a switch statement to make things fit and act properly as well as set a default action if none of the conditions are met.

    I took your original iRule and converted. The "-" at the end of each qualifier tells the iRule that if it qualifies follow the same action as the NEXT item on the list, so in this example all of them will set the HTTP::uri value. If none of them qualify then you will be redirected.

    
    when HTTP_REQUEST {
    switch -glob [string tolower [HTTP::uri]] {
    "/" -
    "/levi_b2b/init.do" -
    "/bd*" { HTTP::uri "/bd/public/frameset_top_html.jsp" }
    default { HTTP::redirect http://leo.levi.com/index.htm }
    }
    }
    

    Hope this helps.