How to Force HTTPS Using .htaccess file

After you buy an SSL certificate and install it on your website, it will be available over HTTP and HTTPS. However, it’s better to use only the latter because it encrypts and secures your website’s data. Use the .htaccess file to force HTTPS connection.

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 File Manager in your hosting panel and open .htaccess inside the public_html folder. If you can’t locate it, make sure to create or unhide it.

Scroll down to find RewriteEngine On and insert the following lines of code below:

 

RewriteEngine On

RewriteCond %{HTTPS} off

RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
 
 
 
Save the changes.
 
 
  • 0 משתמשים שמצאו מאמר זה מועיל
?האם התשובה שקיבלתם הייתה מועילה

מאמרים קשורים

How to Force HTTPS on a Specific Domain

Let’s say that you have two domains: http://yourdomain1.com and http://yourdomain2.com. Both...

How to Force HTTPS on a Specific Folder

The .htaccess (located in your public_html folder)file can also be used to force HTTPS on...

How to install free cPanel SSL

Log into your cPanel account Locate and click on SSL/TLS Manager in the Security section...