Add the code below into the .htaccess file in the root directory of your website:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
You have created a website and then set up SSL for your website, with the hope that visitors who open your website are always served with the HTTPS protocol .
But when you try to type in the domain in the browser, for example yourwebsite.com, the open website still uses the http://websiteanda.com protocol, the padlock icon is still open or red, which means that communication between visitors and the server is still not secure, haven't you? not encrypted properly.
Also read: How to Install Free SSL with Let's Encrypt
RewriteEngine On
Activate the rewrite module , to change the link according to our settings.
RewriteCond %{HTTPS} off
Conditioning the rewrite ( rewrite ) according to certain conditions, in this case if the website is opened with HTTP:// (or if HTTPS is off).
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
The rewrite rule, in this case the HTTP link is changed to HTTPS, and is permanent (301).
That 's how to set a website to always use HTTPS (SSL) when it is opened by visitors who come.
By using HTTPS, visitor data can be more secure, improve user experience and an additional step for search engine ranking optimization Google / Bing (SEO).
Hopefully useful, Happy Digitalyze your life!