Forum Discussion

smp_86112's avatar
smp_86112
Icon for Cirrostratus rankCirrostratus
Jun 24, 2010

Optimizing If statement conditions

I see this examples like this all over the place:


when HTTP_REQUEST {
  if { [HTTP::host] equals "www.myhost.com" and [HTTP::uri] equals "/myuri" } {
    HTTP::redirect https://[HTTP::host][HTTP::uri]
  }
}

I am going though a large number of iRules in an attempt to optimize, and I had a thought occur to me while looking at one of mine like this. Shouldn't I be able to consolidate these two conditions into one, and wouldn't it be more efficient? Something like this?


when HTTP_REQUEST {
  if { [[HTTP::host][HTTP::uri]] equals "www.myhost.com/myuri" } { 
    HTTP::redirect https://[HTTP::host][HTTP::uri] 
  }
}

As a practical matter, this iRule generates an error when it is triggered:

TCL error: www.myhost.com - invalid command name "www.myhost.com/myuri" while executing "[HTTP::host][HTTP::uri]"

 

Assuming I can figure out how to properly write this condition (please help???), wouldn't this be more efficient than writing two conditions to evaluate and then compare? If I can get the syntax right, I'll test it out.