Forum Discussion
Malcolm_Salmons
Nimbostratus
Oct 12, 2005HTTP to HTTPS redirect
Hi
I've currently got a Virtual Server running https, e.g.
https://test.abc.com
This is all working correctly and load balancing happily. However I want to enable redirection of http requests to https, i.e,
http://test.abc.com is redirected to https://test.abc.com
I've created a virtual server on port 80 for http and added the irule below:
when HTTP_REQUEST {
if { [HTTP::uri] eq "test.abc.com"} {
[HTTP::redirect "https://test.abc.com/"]
}
}
However this isnt redirecting traffic to https. Does anybody have any ideas of what I need to do to get this working?
Thanks in advance
Malcolm
6 Replies
- Try removing the brackets around the HTTP::redirect command
when HTTP_REQUEST { if { [HTTP::host] eq "test.abc.com"} { HTTP::redirect "https://test.abc.com/" } }
- rapmaster_c_127Historic F5 AccountYour URI is unlikely to be "test.abc.com"; it's more likely to be "/foo.html", for example. Predicate your check based on the server port instead.
- Mojdeh_Koushki_
Nimbostratus
hello - Brian_Gupta_115
Nimbostratus
I use a generic http2https rule:when HTTP_REQUEST { HTTP::redirect https://[HTTP::host][HTTP::uri] }
- jondyke_46152
Nimbostratus
I already use a similar rule but was wandering how I would do this if I only wanted to redirect to HTTPS with specific URL paths? Would it be worth using a datagroup for this? - hoolio
Cirrostratus
Do you have a list of URIs you want to check for which correspond to a new URI? If so, you could create a string class of source and destination URIs:class uri_redirects_class { "/uri1 /newuri1" "/uri2 /newuri2" }
when HTTP_REQUEST { log local0. "[IP::client_addr]:[TCP::client_port]: New request to [HTTP::host][HTTP::uri]" Check if the requested path is listed in the URI redirects class set new_uri [findclass [HTTP::path] uri_redirects_class] log local0. "[IP::client_addr]:[TCP::client_port]: findclass result: $new_uri" if {$new_uri eq ""}{ Take some default action if the requested path isn't listed in the datagroup? log local0. "[IP::client_addr]:[TCP::client_port]: Didn't find new URI" } else { Redirect client to new location log local0. "[IP::client_addr]:[TCP::client_port]: Redirecting to http://[HTTP::host]$new_uri" HTTP::respond 302 Location "http://[HTTP::host]$new_uri" } }
class uris_to_redirect_class { "/uri1" "/uri2" }
when HTTP_REQUEST { log local0. "[IP::client_addr]:[TCP::client_port]: New request to [HTTP::host][HTTP::uri]" Check if the requested path is listed in the URI redirects class if {[matchlass [HTTP::path] starts_with uris_to_redirect_class]}{ Redirect client to new location log local0. "[IP::client_addr]:[TCP::client_port]: [HTTP::path] matched the class" HTTP::respond 302 Location "http://[HTTP::host]/new_location.html" } else { Take some default action if the requested path isn't listed in the datagroup? log local0. "[IP::client_addr]:[TCP::client_port]: Didn't find new URI" } }
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