Forum Discussion

dundovic_25174's avatar
dundovic_25174
Icon for Nimbostratus rankNimbostratus
Oct 05, 2011

Missing a script after "if"

I'm testing an iRule that'll redirect to a specific site in case both specific user agent and specific cookie are contained in request. I wrote following:

 

 

---

 

when HTTP_REQUEST {

 

if { [class match [HTTP::header "User-Agent"] contains list_of_agents] }

 

if { [HTTP::cookie exists "OREO"] and [HTTP::cookie value "OREO"] ne "empty"} then {

 

HTTP::redirect "http://site1/"

 

log local0.info "REDIR" } else {

 

HTTP::redirect "http://site2"

 

log local0.info "NOREDIR" }

 

}

 

---

 

 

and I'm getting 'Missing a script after "if"' error in line 4. If I use only one of those 'if' lines, it's working fine. Could somebody shed some light where's the problem coming from? I understand it's a syntax issue but I can't figure it out...

 

 

Thanks...

 

 

D.

 

  • can u try this?

    when HTTP_REQUEST { 
       if {[class match [HTTP::header "User-Agent"] contains list_of_agents]} {
          if {[HTTP::cookie exists "OREO"] and [HTTP::cookie value "OREO"] ne "empty"} {
             HTTP::redirect "http://site1/"
             log local0.info "REDIR" 
          } else {
             HTTP::redirect "http://site2"
             log local0.info "NOREDIR" 
          }
       }
    }