Forum Discussion

Andrew_Hinkley_'s avatar
Andrew_Hinkley_
Icon for Nimbostratus rankNimbostratus
May 16, 2007

iRule and default pool

I have this irule applied to a virtual server with a default pool of "MYPOOL", to take an HTTP request and redirect to HTTPS while maintaining the query string. Is the below "else" statement necessary, or will the irule use the default pool if the conditional statement is not matched? In testing it seems to work with the else statement, but I want to verify the functionality.

 

 

rule HTTP_to_HTTPS.login.irule {

 

when HTTP_REQUEST {

 

redirect /root/login.asp to https

 

if { [HTTP::uri] matches_regex "/root/login.asp"} {

 

HTTP::redirect "https://[HTTP::host][HTTP::uri]"

 

} else {

 

pool MYPOOL

 

}

 

}

 

}

 

 

 

 

If I just use the below irule is this functionally equivalent?

 

 

rule HTTP_to_HTTPS.login.irule {

 

when HTTP_REQUEST {

 

redirect /root/login.asp to https

 

if { [HTTP::uri] matches_regex "/root/login.asp"} {

 

HTTP::redirect "https://[HTTP::host][HTTP::uri]"

 

}

 

}

 

}

 

 

-andrew
  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    Yes, the second example should be functionally the same if you have the default pool set on the Virtual.

    Also, as a side note, you can save a lot of processing overhead by replacing your regular expression with a simple equivalence match using either "equals", "ends with" or "contains" as necessary to achieve the result you're looking for.

    Something like"

    
    when HTTP_REQUEST {
       redirect /root/login.asp to https
      if { [HTTP::uri] equals "/root/login.asp"} {
        HTTP::redirect "https://[HTTP::host][HTTP::uri]"
      }
    }

    HTH,

    Colin