Host redirection not working for second host in iRule
Hi,
There is one issue i am facing in redirection - For eg below is the scenerio.
test.com -> https://test.com/redlab/login.html
lab.com -> https://lab.com/bluelab/login.html
We are using single Virtual Server & HTTP::host based irule for backend Pool connectivity.
Tried below irule for redirection - but redirection is working only for first host domain & is not working for second host domain ( for lab.com )
when HTTP_REQUEST {
if {[HTTP::host] equals "test.com" and [HTTP::uri] equals "/"} {
HTTP::redirect "https://test.com/redlab/login.htmll"
if {[HTTP::host] equals "lab.com" and [HTTP::uri] equals "/"} {
HTTP::redirect "https://lab.com/bluelab/login.html"}
}
}
Please let me know, if any modification to be done on abve irule for second host redirection also to work.
You may try Daniel_Wolf solution but your iRule has clear mistakes as the second "if" statement is in the first "if" statemet.
when HTTP_REQUEST {
if {[HTTP::host] equals "test.com" and [HTTP::uri] equals "/"} {
HTTP::redirect "https://test.com/redlab/login.htmll" }
if {[HTTP::host] equals "lab.com" and [HTTP::uri] equals "/"} {
HTTP::redirect "https://lab.com/bluelab/login.html"}
}or even better
when HTTP_REQUEST {
if {[HTTP::host] equals "test.com" and [HTTP::uri] equals "/"} {
HTTP::redirect "https://test.com/redlab/login.htmll"
}elseif {[HTTP::host] equals "lab.com" and [HTTP::uri] equals "/"} {
HTTP::redirect "https://lab.com/bluelab/login.html"}
}Alse this free article for writting irules (the "then" statement is just optional):
https://community.f5.com/t5/technical-articles/irules-101-02-if-and-expressions/ta-p/283431