Prepend 'www' to an HTTPS url using .htaccess & mod_rewrite
- by webfac
I have a dilemma with this one. With the following code I am able to force SSL on any non SSL url, however when the user (and results from Google) take the user to http://mysite.co.za then we hit an issue as the url is then rewritten to https://mysite.co.za
Due to the fact that my certificate is bound to www.mysite.co.za it immediately throws a security error because of the missing 'www' in the url.
Can someone point out a way to add the www to the domain when the domain starts with HTTPS and not HTTP?
Much appreciated.
And the current code to add the https:// is as follows:
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]