04-Feb-2022 22:40
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.
Solved! Go to Solution.
05-Feb-2022 05:02
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
05-Feb-2022 03:38
Hi @Preet_pk,
this iRule will satisfy your requirements:
when HTTP_REQUEST {
if { [string tolower [HTTP::host][HTTP::path]] equals "domain-alpha.com.com/" } {
HTTP::respond 301 -version 1.1 noserver Location "https://domain-alpha.com.com/redlab/login.html"
} elseif { [string tolower [HTTP::host][HTTP::path]] equals "domain-beta.com.com/" } {
HTTP::respond 301 -version 1.1 noserver Location "https://domain-beta.com.com/bluelab/login.html"
} else {
#default action
}
}
I use HTTP::respond instead of HTTP::redirect, because:
HTTP::respond can use 301 / Moved Permanently
HTTP::redirect will alsways use 302 / Found or Temporary Moved
Hope this helps and happy F5 day
Daniel
05-Feb-2022 05:02
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