Forum Discussion

Kenny_Van_73892's avatar
Kenny_Van_73892
Icon for Nimbostratus rankNimbostratus
Oct 24, 2006

Help me with redirect and match cases, please

I just recently upgraded my Big IP units from version 4.5.10 to 4.6.4 to implement new features such as tolower() in irules. The upgrade went well, but when I tried to use tolower() and redirect in a irule, the web page failed to load up.

 

Let say I have a site calls https://www.secure.com/logon/default.aspx and here the irule for the site:

 

if (server_port == 80) {

 

if (tolower(http_uri contains "logon")) {

 

redirect to "https://%h/%u"

 

}

 

else {

 

discard

 

}

 

}

 

else {

 

discard

 

}

 

 

So, here my test: if I type https://www.secure.com/logon/default.aspx then the webpage loads properly, but if I type www.secure.com/logon/default.aspx or WWW.SECURE.COM/LOGON/DEFAULT.ASPX then the webpage just timeout with error message The page cannot be displayed. If I remove tolower(), then type www.secure.com/logon/default.aspx then the irule will redirect to https properly.

 

 

Is there anyway to have tolower() and redirect work together in the same irule? What did I do wrong in the irule above? Please help me out.

 

 

Thanks in advance.

5 Replies

  • Martin_Machacek's avatar
    Martin_Machacek
    Historic F5 Account
    Kenny,

    the correct syntax is:

    
    if (tolower(http_uri) contains "logon") {
       redirect to "https://%h/%u"
    }
    else {
       discard
    }

    The tolower(string) function returns lowercase version of the string you pass it as argument. It does not change the original string. It does not interfere with redirection in any way. Keep in mind though that the URI expanded in place of the %u in the redirect string will have the original capitalization. If you want to insert lowercase version of the URI into the redirection string you need to use:

    
    redirect to "https://" + http_host + tolower(http_uri)

    The test on server_port == 80 is redundant if you attach the rule to a port 80 virtual server, like this:

    
    virtual 1.2.3.4:80 {
       use rule your_rule
    }

    (the server_port is always going to be 80 in this case)
  • Well, I got a chance to test the matching cases irules yesterday. All worked well, except when I modified the above irules little bit, the use pool function never worked out right.

     

    if (tolower(http_uri contains "logon")) {

     

    redirect to "https://" + http_url + tolower(http_uri)

     

    }

     

    else {

     

    use pool my_pool

     

    }

     

     

    For example: when I typed http://www.secure.com/logon/default.aspx, the irules redirected to secure site https:// and this part worked fine; however, when I removed /logon/default.aspx, the irules didn't redirect to http://, instead it still kept https://. So I think the use pool function never worked in this case.

     

    When I configured my_pool, I used http service for all its members.
  • You need to fix the tolower call. It should only have the http_uri as a parameter, instead you have the entire contains condition. This is returning a boolean and the tolower returns a non-zero value which is always interpreted as true so the initial if will always succeed.

    Give this a shot:

    if (tolower(http_uri) contains "logon") {
      redirect to "https://" + http_url + tolower(http_uri)
    }
    else {
      use pool my_pool
    }
  • Sorry my mistake. I actually had if (tolower(http_uri) contains "logon") {....

     

     

    But this way still didn't work. When I typed https://www.secure.com and the irules didn't pass to use pool function which should return to http://.

     

    Thanks for reply.