I want to redirect all users to https://www- version of my website (with htaccess). My problem is that the redirection doesn't work when entering only "www.example.com" in the adress-bar so the browser warns for security. But it works when entering "https://www.example.com".
Here is my code in htaccess:
RewriteEngine On
#first two rows redirects to correct url if non-ssl (if port is not 81)
ReWriteCond %{SERVER_PORT} !^81$
RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R=301,L]
#last two rows correct url if non-www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
The ssl certificates are renewed and the hosting company has helped me set the DNS-records.The PHP version is 5.6 (shared hosting).
Is there any other approach more suitable for shared hosting?
What is wrong with my code?
Thankful for your reply!