Learn F5 Technologies, Get Answers & Share Community Solutions Join DevCentral

Filter by:
  • Solution
  • Technology
Answers

redirect HTTP to HTTPs

Hi

We have f5 load balancer 9.X. Our SSL certificate is loaded in F5. Communication between F5 and webservers are done through port 80. We want to know how to build a I-rule so it can trap response 302 http to redirect to HTTPS. I have open a case with f5 C385918,My support engineer Brant aske me post this request to your site
0
Rate this Question

Answers to this Question

placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER
Hi there,

You should be able to rewrite HTTP to HTTPS with the rewrite redirects option on the HTTP profile associated with your VIP (Click here):


Redirect Rewrite

Specifies whether the system rewrites the URIs that are part of HTTP redirect (3XX) responses. The default setting is None.

* None: Specifies that the system does not rewrite the URI in any HTTP redirect responses.
* All: Specifies that the system rewrites the URI in all HTTP redirect responses.
* Matching: Specifies that the system rewrites the URI in any HTTP redirect responses that match the request URI.
* Nodes: Specifies that if the URI contains a node IP address instead of a host name, the system changes it to the virtual server address.


If you do want to use a rule, you can use something like this:


when HTTP_RESPONSE {

# Enable debug logging to /var/log/ltm? 1=yes, 0=no
set debug 1

# Check if the response is a redirect (3xx)
if {[HTTP::status] starts_with "3"}{

if {$debug}{
log local0. "Original Location: [HTTP::header value Location], Updated Location: [string map {http: https:} [HTTP::header value Location]]"
}

# Use 'string map' to replace http: with https:
HTTP::header replace Location [string map {http: https:} [HTTP::header value Location]]
}
}



Aaron
0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER
Thank you for the script. When we apply the script it failed because of following

Without bracket – way it came



if {[HTTP::status starts_with "3"}{



01070151:3: Rule [ThreeXXredirect] error:
line 7: [parse error: PARSE missingBracket 148 {missing close-bracket}] [{[HTTP::status starts_with "3"}]



0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER
Sorry, I missed the close bracket on HTTP::status. That line should be:

if {[HTTP::status] starts_with "3"}{

Aaron
0