Forum Discussion

AEisiminger_192's avatar
AEisiminger_192
Historic F5 Account
Dec 02, 2010

IRule to Replace http:// with https://

I'm posting this for future users looking for a solution on how to redirect request to https that come in on http.

 

 

This IRule will match the HOST and URI and send the connection back over to the HTTPS VIP.

 

 

when RULE_INIT {

 

Enables or Disables debuging, set to 1 to enable 0 to disable

 

set static::debug 0

 

}

 

when HTTP_REQUEST {

 

Log incoming request information.

 

if { $static::debug } { log local0.alert "[HTTP::host] [HTTP::uri]" }

 

set new_url "https://"

 

append new_url [HTTP::host]

 

append new_url [HTTP::uri]

 

 

HTTP::redirect $new_url

 

 

Log Redirect sting

 

if { $static::debug } { log local0.alert " $new_url" }

 

}

 

1 Reply

  • Hi,

     

     

    Thanks for sharing. Here is another option that should be slightly more efficient as it uses fewer variables and commands.

     

     

    http://devcentral.f5.com/wiki/default.aspx/iRules/HTTPToHTTPSRedirect_301.html

     

     

    Aaron