How to redirect HTTP to HTTPS using .htaccess in wordpress

Posted by: admin
Category: Hosting, Security, Wordpress
HTTPS

One of the most crucial aspects to take into consideration for your online presence is running a secure website. Site security is vital whether you’ve had a website for a while or newly started one, especially for e-commerce companies. Additionally, every website that asks for or saves any kind of user data, even something as essential as login credentials, should offer protection to users.

Why does a website called “not secure”?

You’re probably not new to feeling apprehensive while entering a website if you’ve ever done so and seen a warning that says “not secure” in the search box.

The HTTP websites are not secure

The website connection is not secure

URLs for websites that start with HTTP are not secure. This implies that hackers might steal, view, or alter your login information or, worse yet, your sensitive data like credit card numbers. Further down the page, you may find more information regarding how HTTP impacts site rankings.

The HTTPS websites are secure

On the other hand, URLs for websites that begin with HTTPS are secure. This implies that you won’t notice a “not secure” warning when you see a website address that begins with HTTPS, and you won’t have to worry about hackers stealing the personal information you use on the website. Well-known websites like youtube.com and flipkart.com use HTTPS to reassure users that their transactions are secure.

How to redirect HTTP to HTTPS using .htaccess

HTTP to HTTPS Redirection with .htaccess file modification can be possible by Cpanel or Filezilla:

By Cpanel

1) Go to Cpanel after logging in with your hosting credentials. File Manager

Hostgator File Manager

2) Click on public_html

Hosting public_html panel

3) If your .htaccess file does not appear then go to the top right and click on Setting

Hostgator Hosting Setting

4) A prompt is appearing then check the option Show Hidden Files (dotfiles) and click on the save button

Hostgator cpanel root hidden files

5) Right-click the .htaccess file that appears and edit it.

website file manager modify dot htaccess file

6) Add the below code to the .htaccess file

Method 1:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

secure website code

Method 2: If method 1 will not work for you then you can try the below code

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ HTTPS://yourwebsite.com%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

8) Click on the Save Changes button

Dot htaccess file changes to be saved

By Filezilla

A) Login with Filezilla Credentials then Go to root and download the .htaccess file and add the code that I have used in point number 6 and then upload the file and overwrite it.

Filezilla Root

The website is secured and redirects to HTTPS

The website connection is not secure

I hope this article helps you! If you need any help with this article contact us here!