Published by Iulian Donici on 17.12.2019
and updated on 25.05.2020 at 23:46
This article’s purpose is to show you how to force the web browser redirect your insecure HTTP web site to secure HTTPS by using .htaccess.
Generate your own free OpenSSL certificate for your website.
Create a file called .htaccess and PASTE the following code into it (NOTE: the file must be created inside the root of your website; for example, inside the www/ or public_html/ folder of your website): RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Test your work by typing inside a private window of your web browser, your domain but without the http or www. For example, type just yourdomain.com and check your browser’s return: