Forum Discussion
nich_66940
Nimbostratus
Sep 27, 2007Rewriting 302 redirects
We have come 'intelligent' website code that redirects the user to SSL pages based on what the developer originally thought best.
As we are using SSL offloading on the BigIP this has meant that we need to set the redirect to http to stop the site from performing infinite loops as the site detects that the BigIP has sent the request to port 80, despite the fact that the contention is acceptably secured.
So what I want to do is intercept 302 redirects from the site that match certain URLs and rewrite them to https.
Ie if a redirect from the site tells the user to connect to http://example.com/secure/* I want to redirect it to https://example.com/secure/*
Using the profile option in LTM profiles creates other problems with pages that really should be redirected to port 80.
Going through previously published results I assume I want to do some magic like:
when HTTP_RESPONSE {
if { [HTTP::status] == "302" } {
if { [HTTP::header exists "Location"] } {
if { string compare -nocase -length 26 [HTTP::header "Location"] "http://example.com/secure/" == 0} {
HTTP::header replace "Location" [echo [HTTP::header "Location"] | regexp s/http/https ]
}
}
}
}
Any help is greatly appreciated.
nich.
update: more guesses on my behalf for code needed
- Colin_Walker_12Historic F5 AccountNice work! This looks really close, not to mention tricky! You can simplify it a little though.
when HTTP_RESPONSE { if { [HTTP::status] == "302" } { if { [HTTP::header "Location"] starts_with "http://example.com/secure/" } { HTTP::header replace "Location" [string map {http https} [HTTP::header "Location"] ] } } }
when HTTP_RESPONSE { if { [HTTP::status] == "302" } { switch -glob [string tolower [HTTP::header "Location"] ] { "http://example.com/secure/*" - "http://example.com/private/*" - "http://example.com/restricted/*" - "http://someothersite.com/keepout/*" - "http://reallyprivatestuff.com/shouldbeencrypted/*" - default { HTTP::header replace "Location" [string map {http https} [HTTP::header "Location"] ] } } } }
- nich_66940
Nimbostratus
Thanks that was really helpful. I think I am going to use matchclass due to the number of URLs to rewrite.when HTTP_RESPONSE { if { [HTTP::status] == "302" } { if { [matchclass [string tolower [HTTP::header "Location"]] starts_with $::sslLocations] } { HTTP::header replace "Location" [string map {http https} [HTTP::header "Location"] ] } } }
- mvcheney_65065
Nimbostratus
I've been using a variant of this rule and the upgrade to version 11 has broken it. The variable can no longer be read. Any suggestions? - hoolio
Cirrostratus
mvcheney, - mvcheney_65065
Nimbostratus
Thank you, confirming this solved my V11 issue.
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects