After installing an SSL certificate, your website is available over HTTP and HTTPS.
Hostko allows all users to configure this setting in just one click, you can also use the .htaccess file to force HTTPS connection.
In this tutorial we will show you how.
Redirect HTTP to HTTPS automatically
One of the many functions you can perform via .htaccess is the 301 redirects, which permanently redirects an old URL to a new one. You can activate the feature to force HTTPS on all incoming traffic by following these steps:
- Go to your cPanel > File Manager and open .htaccess inside the public_html folder.
- Scroll down to find RewriteEngine On and insert the following lines of code below it:
RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
After making the changes, clear your browser’s cache and try to connect to your site via HTTP. If everything was added correctly, the browser will redirect you to the HTTPS version.
Congratulations! you have successfully edited your .htaccess file and redirected all HTTP traffic to HTTPS, the safe version of your website.