Forum Discussion
Adam_Borders_10
Aug 18, 2011Nimbostratus
iRule Newbie learning - need validation
I want to validate the this iRule will do as I think. What I want to do is evaluate the request for a redirect to https. If the user connects to domain.com instead of www.domain.com I want to add the ...
hooleylist
Aug 19, 2011Cirrostratus
What would you like to redirect requests to if they are to an IP address? Maybe to that same IP, but via HTTPS?
What about requests with no host header value? What would you like to redirect them to? Most browsers set the host header to an IP if that was what was used. But custom clients may not. Do you use public IP addresses for your virtual servers? If so, you could redirect the client to the virtual server IP over https:
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::host]] {
"www.*" {
Host started with "www.". Allow request without redirecting it?
}
"*[a-z]*" {
Host is not null and not an IP address
HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri]
}
"" {
Host is null
HTTP::redirect "https://default.example.com[HTTP::uri]"
}
default {
Host is an IP address
HTTP::redirect "https://[HTTP::host][HTTP::uri]"
}
}
}
If you're not concerned about requests with no host header, you could remove the redirect to the hardcoded hostname.
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