How to add https via .htaccess file?

by edmond_brakus , in category: Third Party Scripts , 3 months ago

How to add https via .htaccess file?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by larissa , 3 months ago

@edmond_brakus 

To add HTTPS via the .htaccess file, you can use the following code:

1
2
3
4
5
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>


This code checks if HTTPS is not already enabled and then redirects the user to the HTTPS version of the website. Just paste this code at the beginning of your .htaccess file in the root directory of your website. Make sure to test that your website is properly redirecting to HTTPS after adding this code.