Forum Discussion
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
- haridas_175080
Nimbostratus
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
Nimbostratus
There is a space between "else if", change to elseif
- haridas_175080
Nimbostratus
still im facing the same error..
- kunjan
Nimbostratus
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 " } }
- haridas_175080
Nimbostratus
/Common/redirect:3: error: [command is not valid in the current scope][if
- haridas_175080
Nimbostratus
/Common/redirect:3: error: [command is not valid in the current scope][if
- kunjan
Nimbostratus
You get this error while saviing the iRule or executing? If possible share the whole iRule.
- Vijay_E
Cirrus
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.
- haridas_175080
Nimbostratus
Hi All,
Its working fine thank you very much.
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com