Forum Discussion

Joe_Pipitone's avatar
Joe_Pipitone
Icon for Nimbostratus rankNimbostratus
Aug 25, 2009

Redirect rule somewhat working

Hello all,

 

 

I'm having a small issue with an iRule. My rule is below:

 

 

when HTTP_REQUEST {

 

if { [string tolower [HTTP::uri]] equals "/redirectme" } {

 

HTTP::redirect "http://sitename.com/newuri"

 

}

 

}

 

 

This rule works just fine if you type http://sitename/redirectme.

 

 

However, the rule does not redirect if you append a / after, for example:

 

 

http://sitename/redirectme/

 

 

How can I match this so it will redirect both redirectme and redirectme/ ?

 

 

Is this possible using this type of iRule?

 

 

thank you for any help!

3 Replies

  • Try:

     

     

    when HTTP_REQUEST {

     

    if { [string tolower [HTTP::uri]] starts_with "/redirectme" } {

     

    HTTP::redirect "http://sitename.com/newuri"

     

    }

     

    }

     

     

    Kevin
  • You could check for /redirectme or /redirect/me/ with a switch statement:

     
     when HTTP_REQUEST { 
        switch [string tolower [HTTP::uri]] { 
           "/redirectme" - 
           "/redirectme/" { 
              HTTP::redirect "http://sitename.com/newuri" 
           } 
        } 
     } 
     

    Or you could check for anything starting with /redirectme using the -glob flag on switch:

     
     when HTTP_REQUEST { 
        switch -glob [string tolower [HTTP::uri]] { 
           "/redirectme*" { 
              HTTP::redirect "http://sitename.com/newuri" 
           } 
        } 
     } 
     

    Or if you like the 'if' format, you could use this:

     
     when HTTP_REQUEST { 
        if { [string tolower [HTTP::uri]] equals "/redirectme" or [string tolower [HTTP::uri]] equals "/redirectme/" } { 
           HTTP::redirect "http://sitename.com/newuri" 
        } 
     } 
     

    Aaron
  • Thanks guys! As I was searching around I found that starts_with works perfectly! Thanks for your quick responses.