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 http://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]
So you want this:
Your current rule:
This rule fails on you because it adds www no matter whether the connection is secure or not. Additionally, it keeps plain http the way it is (no forward to https://).
The rule that satisfy your requirements above is
The
Lflag is unnecessary because a redirect ends the rewriting.