Jim_Mathers_131
Oct 27, 2014Nimbostratus
simplest method to strip "www." from Host field then HTTPS redirect
Hey folks, my requirements are simple:
-
If the Host header in the HTTP request starts with “www.”, strip “www.” then redirect to HTTPS.
-
If “www.” is not in the Host header, preserve the Host header and redirect to HTTPS.
This is what I came up with:
when HTTP_REQUEST {
if {([string tolower [HTTP::host]] starts_with "www.")} {
HTTP::redirect "https://[string range [HTTP::host] 4 end][HTTP::uri]"
}
else {
HTTP::redirect https://[HTTP::host][HTTP::uri]
}
}
Best way? Looking for the simplest possible solution. I'm new to iRules.