Forum Discussion
irule based on URI to select pool redirected back to http
Hi, I need help here.
I'm using the same VS to create a irule to redirect to different server pools based on URI. The irule which I created redirects back to http which is not what I'm expected.
- test.abc.com -> default poolA -> https://test.abc.com [expected result - OK]
- test.abc.com/testing -> redirects to test.abc.com/homepage -> poolB
- test.abc.com/homepage -> poolB
For both 2. and 3., both were redirected to http://test.abc.com/homepage/login.
SSL offloading is on F5.
I'm expecting https://test.abc.com/homepage/login instead but I'm not getting it.
Any expert advice is appreciated. Thanks!when HTTP_REQUEST {
set host [string tolower [HTTP::host]]
set uri [HTTP::uri]
if { $host contains "test.abc.com"}{
if {([string tolower [HTTP::uri]] starts_with "/testing") }{
HTTP::redirect "https://$host/homepage
pool "poolB"
}
if { [string tolower [HTTP::uri]] starts_with "/homepage" }{
pool "poolB"
}
}
}
- Andy_McGrath
Cumulonimbus
For your iRule, which looks ok but the following is a little improved:
when HTTP_REQUEST { if {[string tolower [HTTP::host]] starts_with "test.abc.com"}{ if {([string tolower [HTTP::uri]] starts_with "/testing") }{ HTTP::respond 301 Location "https://[getfield [HTTP::host] : 1]/homepage" } elseif { [string tolower [HTTP::uri]] starts_with "/homepage" }{ pool "poolB" } } }
If your web server is then doing a redirect it maybe using
protocol instead ofhttp
as the server is listening on HTTP. Should be able to change this setting on the web server so the Location in any redirect HTTP response useshttps
as the protocol or you could write an iRule to change the Location value in any response.https
The following iRules is an example of performing this
header replacement:Location
when HTTP_RESPONSE { if {([HTTP::header exists "Location"]) && ([HTTP::header value "Location"] starts_with "http://test.abc.com"))} { HTTP::header replace "Location" [string map "http://test.abc.com" "https://test.abc.com" [HTTP::header value "Location"]] } }
- Faruk_AYDIN
Nimbostratus
This redirection is made on your servers. You must add your http virtual server a http-to-https redirect iRule.
Have you tried using a combination of your original iRule alongside enabling the redirect rewrite feature on the HTTP profile on the VS? (So that if the backend pool member sends a redirect response using http:// the BIG-IP rewrites this to https://)
https://support.f5.com/csp/article/K14775
- Faruk_AYDIN
Nimbostratus
when HTTP_REQUEST { if { [getfield [HTTP::host] ":" 1] eq "test.abc.com" } { if {([string tolower [HTTP::uri]] starts_with "/testing") || [string tolower [HTTP::uri]] eq "/homepage" }{ HTTP::redirect https://test.abc.com/homepage/login return } else { pool "poolB" } }
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