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 Web site. My objective is to provide HTTP, TCP/80, access to all areas of the Web site except 2 pages, where I want to force the client to redirect to HTTPS, TCP/443. To accomplish this, I have deployed the following rule and assigned it to the HTTP virtual server for the Web site:
when HTTP_REQUEST {
if { [HTTP::uri] contains "/getting_started/contact_email.asp"} {
HTTP::redirect "https://[HTTP::host][HTTP::uri]"
} elseif { [HTTP::uri] contains "/moving/help_request.asp"} {
HTTP::redirect "https://[HTTP::host][HTTP::uri]"
}
}
So far I am happy but...now, once the user has been redirected to HTTPS, they stay on the HTTPS virtual server and never go back to using HTTP for any of the Web site areas. The site is using standard relative paths, so the behavior is understandable; however, it does not work for me. So my questions is...What do I do to redirect clients back to using the HTTP virtual server after they are done using any of the above 2 Web pages?
Thanks for your help.
- 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.
class secure_uris { "/getting_started/contact.asp" "/moving/help_request.asp" }
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]" } }
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]" } }
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]" } } }
- unRuleY_95363Historic F5 AccountJoe,
- Maxim_Taskov_90
Nimbostratus
Thanks for the fast an professional response Joe. Looks like the modified iRule will work perfectly for my case but I will test it and I will post the results here tomorrow. - Maxim_Taskov_90
Nimbostratus
I tested the rule, the one that combines the HTTP and HTTPS logic, and it works perfect. However, I used the "contains" rather than the "starts_with" relational operator considering the fact that the URI will not necessarily start with the path but the class path can be deeper in the URI string. - The only benefit of using "starts_with" over "contains" is to check whether the uri is at the start of the request. There is no significant performance improvement from one to the other.If you use the contains, then all of these requests would match
- Maxim_Taskov_90
Nimbostratus
Thanks for the detailed answer Joe. - Maxim_Taskov_90
Nimbostratus
I spoke too early...everything is good with the rule but I have one small issue...now Internet Explorer alerts you about 6 times that you are moving from secure to non-secure connection before you actually see the page. This happens because the HTTP-to-HTTPS logic send you secure if you visit a certain page, but then the HTTPS-to-HTTP logic sends you non-secure if you are visiting a page other than the one in the specified class. Well, there a number of includes within each page that the HTTPS-to-HTTP logic sends non-secure and the users see the Internet Explorer message multiple times. - You have two options:
- Maxim_Taskov_90
Nimbostratus
Thanks Joe. Your comments were very good and detailed. Unfortunately, I can't use either of them in my environment and I think I will go the path of using a more comprehensive URI class list to avoid the need for negative logic, which is the root cause of the redirect issue. - Andy_Gunter_220
Nimbostratus
Hi Folks,
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