Forum Discussion

haridas_175080's avatar
haridas_175080
Icon for Nimbostratus rankNimbostratus
Oct 31, 2014

trying if else if. not working.. please help me

when HTTP_REQUEST { if { [string tolower [HTTP::host]] equals "abc.com " } { HTTP::redirect "https://abc.com " } else if {

                [string tolower [HTTP::host]] equals "123.com " }
             {
                HTTP::redirect "https://123.com   "
             }
             else
             {
               HTTP::redirect "https://www.xyz.com "
             }
}   

9 Replies

  • I was trying this but getting error. when HTTP_REQUEST { if { [string tolower [HTTP::host]] equals "abc.com " } { HTTP::redirect "https://abc.com " } else if { [string tolower [HTTP::host]] equals "123.com " } { HTTP::redirect "https://123.com " } else { HTTP::redirect "https://www.xyz.com " } }
  • kunjan's avatar
    kunjan
    Icon for Nimbostratus rankNimbostratus

    There is a space between "else if", change to elseif

     

  • kunjan's avatar
    kunjan
    Icon for Nimbostratus rankNimbostratus

    and what error is that .. syntax error?

    when HTTP_REQUEST {
        if { [string tolower [HTTP::host]] equals "abc.com  " }{
            HTTP::redirect "https://abc.com "
        }
        elseif { [string tolower [HTTP::host]] equals "123.com "}{
            HTTP::redirect "https://123.com   "
        } else {
            HTTP::redirect "https://www.xyz.com "
        }
    }
    
  • kunjan's avatar
    kunjan
    Icon for Nimbostratus rankNimbostratus

    You get this error while saviing the iRule or executing? If possible share the whole iRule.

     

  • when HTTP_REQUEST {
        if { [string tolower [HTTP::host]] equals "abc.com  " }{
            HTTP::redirect "https://abc.com"
        } elseif { [string tolower [HTTP::host]] equals "123.com "}{
            HTTP::redirect "https://123.com"
        } else {
            HTTP::redirect "https://www.xyz.com"
        }
    }

    The above rule posted by kunjan seems to be accepted by F5 in 11.x code version.