cancel
Showing results for 
Search instead for 
Did you mean: 

URL and URI redirect

jburford2
Nimbostratus
Nimbostratus

My F5 has one virtual server for all URL's. I need to set a pool based on one of two matching URL's and a matching URI. the code below is what I am trying, the F5 gives me error everytime I try to update the irule.. it doen not like "else or Elseif"

 

 

when HTTP_REQUEST {
    set host [string tolower [HTTP::host]]
    set uri [string tolower [HTTP::uri]]
    if { $host contains ".x." } {
        if { $uri starts_with "/new" } 
            {pool "X_NEW"}
        }		
    Else
    if { $host contains ".y." } {
		if { $uri starts_with "/new" } 
           { pool "Y_NEW"}
        }
}

 

 

 

3 REPLIES 3

harishkarande19
Nimbostratus
Nimbostratus

Please also post error you get, I am suspecting syntax error.

jburford2
Nimbostratus
Nimbostratus
01070151:3: Rule [/Common/KTN_ROUTER] error: /Common/KTN_ROUTER:30: error: [missing a script after "if"][ ]
/Common/KTN_ROUTER:32: error: [undefined procedure: pool "X_NEW"][{pool "X_NEW"}]
/Common/KTN_ROUTER:34: error: [undefined procedure: Else][Else]
/Common/KTN_ROUTER:38: error: [missing a script after "if"][ ]
/Common/KTN_ROUTER:40: error: [undefined procedure: pool "Y_NEW"][{ pool "Y_NEW"}]

when HTTP_REQUEST {
    set host [string tolower [HTTP::host]]
    set uri [string tolower [HTTP::uri]]
    if { $host contains ".x." } {
        if { $uri starts_with "/new" } 
            {pool "X_NEW"}
        }		
    Else
    if { $host contains ".y." } {
		if { $uri starts_with "/new" } 
           { pool "Y_NEW"}
        }
}

T-Trust
Cirrus
Cirrus

Hi I would like to sent solution that relate about your requirement, Please find the irules below,

when HTTP_REQUEST {
set httphost [string tolower [HTTP::host]]
set httpuri [string tolower [HTTP::uri]]

if { ($httphost contains "x1") && ($httpuri starts_with "/y1") } {
pool pool1
} elseif { ($httphost contains "x2") && ($httpuri starts_with "/y2") } {
pool pool2
} else {
pool pool3
}
}

Please find detail of irules in link below, 

https://cloud-ttrust.com/f5-irules-check-http-host-and-uri/