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 redirec...
hoolio
Cirrostratus
Oct 17, 2008Do 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:
class uri_redirects_class {
"/uri1 /newuri1"
"/uri2 /newuri2"
}
Rule:
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"
}
}
Else, if you want to use the same redirect location for a list of URIs, you could define a class with the URIs and use matchclass to check the requested path against it:
Class:
class uris_to_redirect_class {
"/uri1"
"/uri2"
}
Rule:
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"
}
}
Aaron
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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