[HTTP::host] should return "xyz.com" when
https://xyz.com is requested. Try this:
when HTTP_REQUEST {
if { [string tolower [HTTP::host]] eq "xyz.com" } {
HTTP::redirect "https://www.[HTTP::host][HTTP::uri]"
}
}
This iRule needs to go on the https VS, not the http one.
Notice that you don't need to check the port if you only put this iRule on your 443 VS. Keep in mind, however, that if
https://xyz.com results in a certificate error because of a host name mismatch that this error will still be encountered as the request without the www is already being served. Here is a good article on the host name mismatch fun.
https://devcentral.f5.com/Tutorials/TechTips/tabid/63/articleType/ArticleView/articleId/265/Can-iRules-fix-my-cert-mismatch-errors.aspx