Forum Discussion

Robert_47833's avatar
Robert_47833
Icon for Altostratus rankAltostratus
Apr 16, 2012

something interesting in if {if } else

irule

 

if {($uri matches "/cjj" or $uri matches "/cjj/") } {

 

if { [HTTP::host] ends_with ".co.uk" } {

 

HTTP::redirect "http://[HTTP::host]/error.html"

 

return

 

}

 

}

 

else {

 

pool xxxx

 

}

 

 

http://www.ss.com/cjj doesn't hit pool xxxx,why?

 

 

this url doesn't match ".co.uk",why irule doesn't pass it to else?

3 Replies

  • Hi Jucao,

    www.ss.com/cjj would match the first if but not the second. So it wouldn't hit the pool statement. If you want to use that pool for www.ss.com/cjj, you could try this:

    
    if {($uri matches "/cjj" or $uri matches "/cjj/") } {
    if { [HTTP::host] ends_with ".co.uk" } { 
    HTTP::redirect "http://[HTTP::host]/error.html" 
    return 
    } else {
    pool xxxx
    }
    } else {
    pool xxxx
    }
    

    Aaron
  • ok,I see

     

    once /cjj is matched,but no action is in irule,F5 will send fallback host(fallback host is configured) to client,right?
  • yes

    [root@ve1023:Active] config  b virtual bar list
    virtual bar {
       snat automap
       destination 172.28.19.79:80
       ip protocol 6
       rules myrule
       profiles {
          myhttp {}
          tcp {}
       }
    }
    [root@ve1023:Active] config  b profile myhttp list
    profile http myhttp {
       fallback "http://www.google.com"
    }
    [root@ve1023:Active] config  b rule myrule list
    rule myrule {
       when HTTP_REQUEST {
       set uri [HTTP::uri]
       if {($uri matches "/cjj" or $uri matches "/cjj/") } {
          if { [HTTP::host] ends_with ".co.uk" } {
             HTTP::redirect "http://[HTTP::host]/error.html"
             return
          }
       } else {
          pool foo
       }
    }
    }
    [root@ve1023:Active] config  curl -I http://www.ss.com/cjj
    HTTP/1.0 302 Found
    Location: http://www.google.com
    Connection: close