Forum Discussion

Phaneath_Phour1's avatar
Phaneath_Phour1
Icon for Nimbostratus rankNimbostratus
Aug 17, 2018

Redirect HTTP to HTTPS

Hello DC,

 

I'm new with F5 iRule. And right now, I have an application using http port 8080 and I would like to use SSL offload between client to F5 and keep the same port 8080 with https.

 

I create a VS using SSL and port 8080. It's working to display a login page with URL (), but when we logged in the application redirect to http and port 8080 () then I need to insert https manually on URL then it's working.

 

So, I would like to ask anyone can provide me the sample iRule to insert HTTPS when we perform logged in.

 

Thanks,

 

Phaneath

 

4 Replies

  • This has been asked often and multiple threads are there.

    Offloading SSL traffic causes improper redirects or links to HTTP

    The solution was to update the http response headers, something like below.

    when HTTP_RESPONSE {
        if { ( [HTTP::header exists Location] ) and ( [HTTP::header Location] contains "http://" ) } {
            HTTP::header replace [string map -nocase {"http://" "https://"} [HTTP::header Location]]
        }
    }
    
  • You should create a Virtual Server listen on 8080 without SSL offload and assign an irule/LTM policty to redirect all HTTP request to HTTPS request at another port ( e.g 8443).

    when HTTP_REQUEST { 
    HTTP::redirect "https://[HTTP::host]:8443[HTTP::uri]" 
    }
    

    Create another Virtual Server listen on another port (8443) with SSL offload and assign this irule to rewrite redirect port if has

    when HTTP_RESPONSE {
     Check if server response is a redirect
    if { [HTTP::header is_redirect]} {
        HTTP::header replace Location https://[string map {"http://" ""} [string map ":[TCP::remote_port]/ :8443/" [HTTP::header value Location]]]
       }
    }
    
    • Phaneath_Phour1's avatar
      Phaneath_Phour1
      Icon for Nimbostratus rankNimbostratus

      Hello Quantiti,

       

      It fixed my problem with iRule now. Thank you so much!!

       

      Best Regards, Phaneath