Forum Discussion

craig_jones_103's avatar
craig_jones_103
Icon for Nimbostratus rankNimbostratus
Mar 22, 2009

Newbe to Irules and I need Help Urgently

Hi there Folks.

 

 

I am new to F5 and this is the First IRule that I am trying to get operating and as usual it needed in a rush.

 

We have a web site "http://a.b.com and normall all traffic to this has to be redirected to HTTPS://a.b.com except that is if the URL is http://a.b.com/cd.xml na dif it is we need it to go to the pool "POOL_A.B.COM" on http.

 

 

I have tried the following rules with the errors given.

 

IRULE

 

when HTTP_REQUEST {

 

if {[HTTP::uri] equals {ws.digitalrecordcenter.com/crossdomain.xml}} {snat 10.195.3.162} {pool POOL_WS.DRC.COM_EN

 

} else {HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri]

 

}

 

}

 

ERROR

 

01070151:3: Rule [Irule_WS.HTTP-to-HTTPS_301] error:

 

line 2: [deprecated usage, use else or elseif] [ ]

 

line 2: [undefined procedure: else] [if {[HTTP::uri] equals {ws.digitalrecordcenter.com/crossdomain.xml}} {snat 10.195.3.162} {pool POOL_WS.DRC.COM_EN

 

} else {HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri]

 

}]

 

and also

 

IRULE

 

when HTTP_REQUEST {

 

if {[HTTP::uri] equals "ws.digitalrecordcenter.com/crossdomain.xml"} {

 

snat 10.195.3.162} {pool POOL_WS.DRC.COM_EN

 

}

 

elseif {[HTTP::uri] equals "ws.digitalrecordcenter.com"} {

 

HTTP::redirect https://ws.digitalrecordcenter.com/]

 

}

 

}

 

ERROR

 

01070151:3: Rule [Irule_WS.HTTP-to-HTTPS_301] error:

 

line 3: [deprecated usage, use else or elseif] [ ]

 

line 2: [undefined procedure: elseif] [if {[HTTP::uri] equals "ws.digitalrecordcenter.com/crossdomain.xml"} {

 

snat 10.195.3.162} {pool POOL_WS.DRC.COM_EN

 

}

 

elseif {[HTTP::uri] equals "ws.digitalrecordcenter.com"} {

 

HTTP::redirect https://ws.digitalrecordcenter.com/]

 

}]

 

 

Can any of you guys give an explanation to a complete novice as to what the Irule might be or where I am going wrong on this.

 

 

any help you can offer would be greatly apprecaited.

 

 

Regards.

 

 

Craig Jones

 

1 Reply

  • TCL is pretty specific about where you put curly braces and the else statement. I think what the issue is is the two sets of statements (snat and pool) between the "if" and "else". Also, A URL is the form of "protocol:[HTTP::host][HTTP::uri]" so you should leave out the ws.digiticalrecordcenter.com out of the comparison. Also, I prefer to use a switch statement as it's a little better performing than an if.

    Give this a shot:

    when HTTP_REQUEST { 
       switch [string tolower [HTTP::uri] { 
         "/crossdomain.xml" { 
           snat 10.195.3.162 
           pool POOL_WS.DRC.COM_EN 
         } 
         default { 
           HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri] 
         } 
       } 
     }

    Another bonus with switch, is that you can use "glob" based wildcards which are faster than regular expressions. So, if you wanted to match based on a pattern you could do something like this:

    when HTTP_REQUEST { 
       switch -glob [string tolower [HTTP::uri] { 
         "/*.xml" { 
           snat 10.195.3.162 
           pool POOL_WS.DRC.COM_EN 
         } 
         default { 
           HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri] 
         } 
       } 
     }

    If you want to go the "if" route, it would look like this.

    when HTTP_REQUEST { 
       if { [string tolower [HTTP::uri] equals "/crossdomain.xml" } { 
         snat 10.195.3.162 
         pool POOL_WS.DRC.COM_EN 
       } else { 
         HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri] 
       }    
     }

    One more thing. You didn't mention in your requirements that you needed to snat the connection. What's the reason for including the "snat 10.195.3.162" statement? If a snat is not needed, you might want to leave that one out.

    Hope this helps...

    -Joe