Forum Discussion

justinhamlin_14's avatar
justinhamlin_14
Icon for Nimbostratus rankNimbostratus
Aug 25, 2017

If / else not working

BigIP v11.5.1

Attempting to write an irule that redirects to different pools based on URI - super basic, but for some reason when adding the rule into the LTM console, it errors out when using ELSE. If I update it to use ELSEIF then it works. However, the logic as it is below is how I would like it, only if it sees the URI of /loyaltyapi does it redirect, otherwise it goes to the default pool for the Virtual Server.

Here is my iRule

when HTTP_REQUEST { 
   if { [string tolower [HTTP::path]] starts_with "/loyaltyapi" } {
    pool rcv100crw-pool-http
   }
   else {
    pool rcv100cwb-pool-http
   }
}

when I put that into the LTM, I get the following errors:

01070151:3: Rule [/Common/api_redirect_http] error: /Common/api_redirect_http:2: error: [undefined procedure: &160][ ] /Common/api_redirect_http:5: error: [undefined procedure: else][else { pool rcv100cwb-pool-http }]

Any guidance would be greatly appreciated.

2 Replies

  • nathe's avatar
    nathe
    Icon for Cirrocumulus rankCirrocumulus

    Justin, if you're using the default pool why not remove the else statement altogether?

     

    The irule does look ok to be honest, but not at my bigip to confirm 100%.

     

    N

     

  • Hi,

    this kind of error appears when there is issue with missing space between curly brackets or something like that. thy this!

    when CLIENT_ACCEPTED { 
        set default_pool [LB::server pool]
    }
    
    when HTTP_REQUEST { 
        if { [string tolower [HTTP::path]] starts_with "/loyaltyapi" } {
            pool rcv100crw-pool-http
        } else {
            pool $default_pool
        }
    }