Forum Discussion

Sekhar's avatar
Sekhar
Icon for Nimbostratus rankNimbostratus
Feb 20, 2015

TCL Error

HI, I am seeing the following error in our LTM logs. Please help in spotting the error in irule.

 

Error:

 

TCL error: /Common/IR_abc_Redirect - can't use non-numeric string as operand of "||" while executing "if { [string tolower [HTTP::host]] equals "www.abc.com" or "abc.com" or "a.b.c.d" } { HTTP::respond 301 Location ""

 

irule: when HTTP_REQUEST { if { [string tolower [HTTP::host]] equals "www.abc.com" or "abc.com" or "a.b.c.d" } { HTTP::respond 301 Location "http://wp.abc.com/" } }

 

Thanks,

 

Sekhar

 

1 Reply

  • Using the statement "If" would look like this:

    if { [string tolower [HTTP::host]] equals "www.abc.com" or [string tolower [HTTP::host]] equals "abc.com" or [string tolower [HTTP::host]] equals "a.b.c.d" } { 
        HTTP::respond 301 Location "http://wp.abc.com/" 
    } 
    

    Replace the "if" statement by "switch", something like this:

    switch [string tolower [HTTP::host]] {
        "www.abc.com" -
        "abc.com" -
        "a.b.c.d" { 
            HTTP::respond 301 Location "http://wp.abc.com/" 
        }
    } 
    

    https://www.tcl.tk/man/tcl8.4/TclCmd/switch.htm

    Hope this helps.