Forum Discussion
Host redirection not working for second host in iRule
- Feb 05, 2022
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
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
}
}
- The 301 response code indicates that the requested page has been permanently moved to the URL given in the Location header.
- -version 1.1 will set HTTP/1.1 (otherwise HTTP/1.0 would be used).
- noserver will prevent that the default server header (configured in HTTP profile, usually BigIP) is returned to the client.
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
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