Forum Discussion

DM_5174's avatar
DM_5174
Icon for Nimbostratus rankNimbostratus
Mar 11, 2011

independant from case-sensitive URI path httpS redirect

Hi All,

I was wondering if I could get some help from all of the i-rule gurus here.

Below is an i-rule we have that will 1) add "www" to the URI if a user forgets to put it in, and

2) if the user specify "/Mgt/Portal/LogOn" in the URI (for example http://www.abc.test.com/Mgt/Portal/LogOn" they will get redirected to HTTPS "httpS://www.abc.test.com/Mgt/Portal/LogOn".

Currently we only want to trigger this because by default site www.abc.com should NOT be HTTPS.

1. Is there a way to make it where if the the path "/Mgt/Portal/LogOn" can independant from case-sensitive charaters? So if the user puts /MgT/porTal/login" you still get HTTPS

2. And also consolidate this into a effcient irule and not use two "if" statment?

Thanks all in advance!

-DM


 when HTTP_REQUEST { 
             if { [HTTP::host] equals "abc.test.com" } { 
                   HTTP::redirect "http://www.abc.test.com[HTTP::uri]" 
                } 
             if { [HTTP::path] equals "/Mgt/Portal/LogOn" } { 
                  HTTP::redirect "https://www.abc.test.com[HTTP::uri]" 
                } 
  • 1. Use "string tolower" before whatever you're trying to check.

    2. Since your redirects are different, an if might be best.

    
    when HTTP_REQUEST {
              if { [HTTP::host] eq "abc.test.com" } {
                    HTTP::redirect "http://www.abc.test.com[HTTP::uri]" 
             } elseif { [string tolower [HTTP::uri]] starts_with "/mgt/portal/login" } {
                    HTTP::redirect "https://www.abc.test.com[HTTP::uri]" }
            }
    

    Interested to see if others have tips on optimizing.
  • Hi Chris,

     

     

    For some reason this did not work. We need to make it exactly like this "/Mgt/Portal/LogIn" since the link is case-sensitive on the backend server no matter how the user puts in the uri path.

     

     

    For example if the users puts http://www.abc.test.com/mgt/portal/login in the address bar, they should get https://www.abc.test.com/Mgt/Portal/LogIn" by the i-rule.

     

     

    Also, this rule also disable the function where users adding in "abc.test.com/abc", it does not append the "www". It shoudl be http"//www.abc.com/abc".

     

     

    Thanks again,

     

     

    -DM

     

     

  • Try this:

    
    when HTTP_REQUEST {
              if { [HTTP::host] eq "abc.test.com" } {
                    HTTP::redirect "http://www.abc.test.com[HTTP::uri]" 
             } elseif { [string tolower [HTTP::uri]] starts_with "/mgt/portal/login" } {
                    HTTP::redirect "https://[HTTP::host][HTTP::uri]" }
            }
    
  • Wait - are you saying someone who puts in abc.test.com/abc isn't being redirected to www.abc.test.com/abc ?

     

     

    The redirect will honor the case. The user's request is stored in [HTTP::uri] so referencing that within the redirect keeps it as is.

     

     

    Currently - what's the behavior you're seeing and what would you like to see? ;)
  • I think I see what He's looking for..

     

     

    For some reason this did not work. We need to make it exactly like this "/Mgt/Portal/LogIn" since the link is case-sensitive on the backend server no matter how the user puts in the uri path.

     

     

     

    He wants the actual redirect to be case sensitive, but the detection to be insensitive... Soo, after to you set your string to lower for the detection, specify the actual uri for redirection, "/Mgt/Portal/LogIn"

     

     

    Not sure either why the append for 'www' isn't working for you, looks fine..

     

  • DM - can you confirm iRuleYou is describing what you want to see? I guess we could do some sort of string map for this.
  • Hey Guys,

     

     

    When I used "/Mgt/Portal/LogIn" It worked (gave me httpS) even if I went in with lower case. The funny thing is when I specify the opposite, lower case "/mgt/portal/login", it does not redirect me to httpS. For some reason our application requires specific case sensitive letters in order to present you with the login page, but now I am getting the SSL connection and everything else seems to work when I re-ordered things around in the code.

     

     

     

    I think we are good. Thanks Chris!

     

     

    -DM