Forum Discussion
yihwen_100254
Jun 14, 2011Nimbostratus
Generic iRule to redirect domain.com to www.domain.com
Hi
I am planning to create an generic iRule to perform a http://domain.com to https://www.domain.com I know in the F5 v10.x.x, there is a _sys_https_redirect and that will actually redirect ...
hooleylist
Jun 15, 2011Cirrostratus
Can you try this instead?
when HTTP_REQUEST {
log local0. "[IP::client_addr]:[TCP::client_port]: [HTTP::method] to [HTTP::host][HTTP::uri]"
switch -glob [string tolower [HTTP::host]] {
"www.*" {
HTTP::redirect "https://[HTTP::host][HTTP::uri]"
log local0. "Redirecting www host to https://[HTTP::host][HTTP::uri]"
}
{*[a-z]*} {
HTTP::redirect "https://www.[HTTP::host][HTTP::uri]"
log local0. "Redirecting non-www host to www.[HTTP::host][HTTP::uri]"
}
"" {
HTTP::redirect "https://[IP::local_addr][HTTP::uri]"
log local0. "Redirecting null host to [IP::local_addr][HTTP::uri]"
}
default {
HTTP::redirect "https://[HTTP::host][HTTP::uri]"
log local0. "Redirecting IP address [HTTP::host] to https://[HTTP::host][HTTP::uri]"
}
}
}
Sample log output for each case:
< HTTP_REQUEST >: 10.1.0.11:54026: GET to www.example.com/test
< HTTP_REQUEST >: Redirecting www host to https://www.example.com/test
< HTTP_REQUEST >: 10.1.0.11:54027: GET to example.com/test
< HTTP_REQUEST >: Redirecting non-www host to www.example.com/test
< HTTP_REQUEST >: 10.1.0.11:54028: GET to /test
< HTTP_REQUEST >: Redirecting null host to 10.1.0.15/test
< HTTP_REQUEST >: 10.1.0.11:54030: GET to 10.1.0.15/test
< HTTP_REQUEST >: Redirecting IP address 10.1.0.15 to https://10.1.0.15/test
Aaron
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