Forum Discussion
Jim_Mathers_131
Nimbostratus
Oct 27, 2014simplest 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.
1 Reply
- Matt_Dierick
Employee
It's perfect :)
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