Forum Discussion

Steve_Sutton_87's avatar
Steve_Sutton_87
Icon for Nimbostratus rankNimbostratus
Apr 29, 2005

using matches_regex - strange error

Hi,

 

 

I've been trying to create a rule which will detect the user supplying a path with incorrect case and redirect using the correct case for the path. The rule is this:

 

 

if (http_uri == "/" or http_uri matches_regex "/[Ee][Pp][Mm]1/?") {

 

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

 

log "redirected blank URI"

 

}

 

else {

 

use pool main-qa-8080

 

}

 

 

The idea being that if they type /epm1, or /ePm1, or /EPM1/, etc., the will get redirected to the correct /Epm1. Now if I access the site with *any* path specified, I get a popup error message about redirection limit for the URL exceeded (full message attached).

 

 

Now, this isn't really critical, it was mostly an experiment to see if we could do this, but I'm hoping someone can clue me in as to why I'm getting the error - I've no clue, really, why I'm getting it.

 

 

Cheers,

 

Steve

 

2 Replies

  • Scott_Tennican_'s avatar
    Scott_Tennican_
    Historic F5 Account
    The problem is that your regular expression matches the correct uri as well as incorrect ones. So, you never stop redirecting.

     

    Instead, check for the correct uri first.

     

    Adding the code below to the top of your if statement should help.

     

     
     if (http_uri == "/Epm1") { 
        use pool main-qa-8080 
     } 
     else ... 
     

     

     

    Also, be aware that the matches_regex operation is very computationally expensive in v4.X. You might check out the tolower() rule function introduced in v4.6.1.
  • Ah ... well of course, that makes perfect sense. Thanks, gumby.

     

     

    Cheers,

     

    Steve