cancel
Showing results for 
Search instead for 
Did you mean: 

Multiple domain redirection

Preet_pk
Nimbostratus
Nimbostratus

Hi,

There is one requirement to redirect 2 Host domains -

lab.com  -> https://lab.com/bluelab/login.html

uatlab.com -> https://uatlab.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 not working for both host domains

when HTTP_REQUEST {
if {[HTTP::host] equals "lab.com" and [HTTP::uri] equals "/"} {
HTTP::redirect "https://lab.com/bluelab/login.html"
if {[HTTP::host] equals "uatlab.com" and [HTTP::uri] equals "/"} {
HTTP::redirect "https://uatlab.com/bluelab/login.html"}
}
}

Once i tried below irule  on VS redirection started working for lab.com

irule lab.com-redirection
when HTTP_REQUEST {
if { [HTTP::host] equals "lab.com"} {
if { [HTTP::path] equals "/" }
{
HTTP::redirect "https://lab.com/bluelab/login.html"
}
}

but once below irule is applied  on same VS along with above irule both host domain rediection stopped working & even both site went down.

irule uatlab.com-redirection
when HTTP_REQUEST {
if { [HTTP::host] equals "uatlab.com"} {
if { [HTTP::path] equals "/" }
{
HTTP::redirect "https://uatlab.com/bluelab/login.html"
}
}

Please share the irule for multiple host redirection to be configured on a single irule & can be applied to a signle VS.

2 REPLIES 2

Hi Preet_pk,

You are probably getting a tcl error, you can see it in the ltm logs.
https://support.f5.com/csp/article/K23237429

when HTTP_REQUEST {
    if {[HTTP::has_responded]} { return }
    if {[HTTP::host] equals "lab.com" and [HTTP::uri] equals "/"} {
        HTTP::redirect "https://lab.com/bluelab/login.html"
        return
    elseif {[HTTP::host] equals "uatlab.com" and [HTTP::uri] equals "/"} {
        HTTP::redirect "https://uatlab.com/bluelab/login.html"}
        return
    }
}

shorter:

when HTTP_REQUEST {
    if { [HTTP::has_responded] } { return }
    if { [HTTP::uri] eq "/" and ([HTTP::host] eq "lab.com" or [HTTP::host] eq "uatlab.com") } {
        HTTP::redirect "https://[HTTP::host]/bluelab/login.html"
        return
    }
}

 

Ahmed_Galal
Cirrostratus
Cirrostratus

you can configure LTM policy condtion based on hostname and URI and action with redirection URL.