irule redirect http to https://www. but not if www?

This should be easy for you guys.

I"m still a little new to iRules. I believe this is a simple one, but time constraints are leading me to post this here:

I’m need to do a 301 redirect for any going to or mysite.com to https://www.mysite.com

Here was my initial attempt:

when CLIENT_ACCEPTED { if {[TCP::local_port] eq 443 } {set SSL 1} else {set SSL 0} } when HTTP_REQUEST { if {!$SSL} { HTTP::respond 301 Location “.[HTTP::host][HTTP::uri]” } }

You should already see the problem.

It redirects to https://www.www.mysite.com.

what am I missing??

Heya,

You can apply the following to your HTTP virtual server if you want to redirect all requests to HTTP along with the addition of "; :

when HTTP_REQUEST {
  HTTP::respond 301 Location "https://www.[HTTP::host][HTTP::uri]"
}