How do I write a rule to redirect someone from the virtual server “stuff” to the virtual server “stuff-ssl”? We need to force users who do not enter the “https://” to go to the SSL site. I don’t normally write code and the samples do not seem to work. Is there another way besides an iRule to do a forced redirect?
A search for “redirect https” leads to this example:
when HTTP_REQUEST {
HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri]
}
All requests to the VIP will be redirected to HTTPS. If the original request contains a port in the host header field, it will be removed. So a request to:
I tried that rule, but it did not work. I created the rule and associated it to the appropriate pool, but the outcome did not change. I still need to type https to get to the website.
FYI: The getfield command splitting hostname on the “:” was included in the codeshare rule to make the rule compatible with http virtuals running on non-standard ports.
If a “:” is present in [HTTP::host] (because a non-standard port is included in the Host header in the inbound request), only the characters preceding it (the actual hostname) are returned.
If no “:” is present in the hostname, the entire string is returned.
when HTTP_REQUEST {
log local0. "received request from [IP::remote_addr]. Redirecting to https://[getfield [HTTP::host] ":" 1][HTTP::uri]"
HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri]
}
And verified that I get redirected correctly. Here is the log entry from /shared/log/ltm:
Aug 3 13:22:14 tmm tmm[7333]: Rule http_https_redirect : received request from 192.168.151.88. Redirecting to https://172.29.0.217/
From the error, it looks like there might be an extra double quote in the log statement after the word ‘from’. Can you comment out the log statement with a and retest?