When I applied this and opened http://website.com it just redirected to https://website.com. I used the iRule Redirection generator to create the first part of the if/else but it doesn’t appear to be triggering off http://website.com like I thought it would.
2. [HTTP::uri] is typically “/” for a home page, it’s basically the part after the host and before queries, paths, etc.
In your case, you’re looking for a URI to equal “website.com” which will never happen. Also, by using HTTP::uri on the line after, you’re essentially rewriting the URI on the way to your pool member. The reason you were redirected to https://website.com is because you met your else statement.
Try this:
when HTTP_REQUEST {
if { [string tolower [HTTP::host]] eq "website.com"} {
HTTP::redirect "https://[HTTP::host][HTTP::uri]" } }
Instead of “eq”, you could also use “starts_with” as some clients/browsers will send you hosts like “website.com.”
That iRule should have the same effect regardless of the requested host. So you should be able to simplify the rule a bit and always redirect to https://[HTTP::host][HTTP::uri] without checking the requested host.
when HTTP_REQUEST {
HTTP::redirect "https://[HTTP::host][HTTP::uri]"
}
Sorry, Chris. I think I misread the original intent. I’m guessing the original poster is trying to handle example.com and www.example.com resolving to the same IP with a single cert valid only for www.example.com. So maybe it would be safer to redirect all requests to https://www.example.com[HTTP::uri] rather than using [HTTP::host] to insert the originally requested host in the redirect?