Forum Discussion

Sean_Lagerholm_'s avatar
Sean_Lagerholm_
Icon for Nimbostratus rankNimbostratus
Jan 24, 2006

iRule syntax problems

I keep getting an error that I'm missing a close brace. I'm trying to implement the following irule :

 

 

rule myweb_service {

 

when HTTP_REQUEST {

 

if {[HTTP::host] eq "mysite1.com"} {

 

pool mysite1.com

 

} else if {

 

[HTTP::host] eq "mysite2.com" } {

 

pool mysite2.com

 

} else if {

 

[HTTP::host] eq "mysite3.com" } {

 

pool mysite3.com

 

} else if {

 

[HTTP::host] eq "mysite4.com" } {

 

pool mysite4.com

 

} else if {

 

[HTTP::host] eq "mysite5.com" } {

 

pool mysite5.com

 

} else if {

 

[HTTP::host] eq "mysite6.com" } {

 

pool mysite6.com

 

} else if {

 

[HTTP::host] eq "mysite7.com" } {

 

pool mysite7.com

 

}

 

else { discard

 

}

 

}

 

 

I'm not seeing the missing close brace. Can someone give me a hand here? Thanks!
  • A couple of points.

    1) remove the "rule" enclosure unless you are editing from the configuration file directly.

    2) use "elseif" instead of "else if".

    when HTTP_REQUEST {
      if { [HTTP::host] eq "mysite1.com" } {
        pool mysite1.com
      } elseif { [HTTP::host] eq "mysite2.com" } {
        pool mysite2.com
      } elseif { [HTTP::host] eq "mysite3.com" } {
        pool mysite3.com
      } elseif { [HTTP::host] eq "mysite4.com" } {
        pool mysite4.com
      } elseif { [HTTP::host] eq "mysite5.com" } {
        pool mysite5.com
      } elseif { [HTTP::host] eq "mysite6.com" } {
        pool mysite6.com
      } elseif { [HTTP::host] eq "mysite7.com" } {
        pool mysite7.com
      } else { 
        discard
      }
    }

    You could also make this much cleaner by using an external data group (do a search for matchclass/findclass in the forums).

    -Joe