Prepend 'www' to an HTTPS url using .htaccess & mod_rewrite

Posted by webfac on Stack Overflow See other posts from Stack Overflow or by webfac
Published on 2010-05-25T06:53:27Z Indexed on 2010/05/25 11:41 UTC
Read the original article Hit count: 279

Filed under:
|
|

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]

© Stack Overflow or respective owner

Related posts about apache

Related posts about .htaccess