Forum Discussion
Maxim_Taskov_90
Nimbostratus
Mar 07, 2006HTTP to HTTPS and Back
Hi, I am sorry if this question has been asked before but I could not find an answer anywhere...including F5 Tech Support.
I have two virtual servers, one HTTP and one HTTPS, for the same We...
Mar 07, 2006
I'm assuming from your post that you have two virtual servers (one for HTTP and one for HTTPS). If that is the case you can have two rules with the reverse logic in each.
I'd also suggest using a class list (data group) to contain your urls. It's much easier to manage that way and then you can change them in one place if you need to. You'll need to add these values into a data group in the iRules section of the GUI. If you don't want to use a data group, you can replace the if statement with two string compares separated by a logical OR.
class secure_uris {
"/getting_started/contact.asp"
"/moving/help_request.asp"
}
For your HTTP virtual do something like this:
when HTTP_REQUEST {
if the uri starts with one of the values in the
secure_uris list, then redirect to the HTTPS version
if { [matchclass [HTTP::uri] starts_with $::secure_uris] } {
HTTP::redirect "https://[HTTP::host][HTTP::uri]"
}
}
For your HTTPS virtual:
when HTTP_REQUEST {
if the uri doesn't start with one of the values in the
secure_uris list, then redirect to the HTTP version
if { ! [matchclass [HTTP::uri] starts_with $::secure_uris] } {
HTTP::redirect "http://[HTTP::host][HTTP::uri]"
}
}
Or, if you want a single rule that you can apply to both virtuals, you can distinguish HTTP vs. HTTPS via the TCP::local_port value.
when HTTP_REQUEST {
if { [TCP::local_port] == 80 } {
if the uri starts with one of the values in the
secure_uris list, then redirect to the HTTPS version
if { [matchclass [HTTP::uri] starts_with $::secure_uris] } {
HTTP::redirect "https://[HTTP::host][HTTP::uri]"
}
} else {
if the uri doesn't start with one of the values in the
secure_uris list, then redirect to the HTTP version
if { ! [matchclass [HTTP::uri] starts_with $::secure_uris] } {
HTTP::redirect "http://[HTTP::host][HTTP::uri]"
}
}
}
This hasn't been tested, but should give you something to get you going.
-Joe
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