How to properly redirect http to https in htaccess editor of hosting ?

Hello everyone,  Today we are about to discuss incomplete about the redirection of your http to https protocol. The easiest and friendly way to simply redirect the domains is by making an edit in the .htaccess file in your hosting account. Its simple and can be done by you easily.

Here you will learn about how to redirect your website from http to https by using a .htaccess file. The servers that are based on the Linux use .htaccess file to encrypt the coding. You can find your website .htaccess file n your root folder of the website where you may have installed the WordPress for your website. If there is no root file named as .htaccess , then you can create new one easily.

Redirect http to https by htaccess in ‘wordpress site’

If you have your website installed with WordPress, then its easy and you will find a file in the name of .htaccess , simply open that file. The default .htaccess file that you will find in your root will be containing the following rules:

# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

You will see this code in your .htaccess file. This is the by default coding defining your WordPress website execution rules from your hosting or the root folders that you have saved in.

Since in order to get secured by the hackers and the threats that may occur online, A SSL certificate is needed.

What is SSL Certificate?

SSL stands for Secure Sockets Layer, the protocol which provides the encryption. SSL Certificates are typically installed on pages that require end-users to submit sensitive information over the internet like credit card details or passwords.

When you purchase and install the SSL certificate on your website, then your protocol changes from http:// to https:// in a browser and your browser start indicating a safe connection. However if the URL entered to your website is in the form of HTTP, then a user will visit a non-secure version of your website. Thus in order to redirect the user to secure version of your website, you simply need to redirect the users through your hosting. Thus you need to have a redirection to https by editing your .htaccess file.

Code for redirecting http to https wordpress website :

# BEGIN WordPress
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.site.com [NC]
RewriteRule ^(.*)$ https://site.com/$1 [L,R=301]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^site.com [NC]
RewriteRule ^(.*)$ https://site.com/$1 [L,R=301]
RewriteBase /
RewriteRule ^index\.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

Replace the ‘site‘ name with your website.

You simply need to copy this above code and paste it to your .htaccess editor.

After you have made these changes, you need to visit your WordPress dashboard, in order to make a slight change that is, you need to go to Settings->General Settings and change WordPress address url and site address url to https

NOTE: After making all the changes please make sure to not to visit the Permalinks option in your WordPress website, as it may harm your link structure and again your saved setting for .htaccess file will be completely lost.

In case of any problems or queries, please comment in the box below or contact us. Thank You.

Leave a Reply

Your email address will not be published. Required fields are marked *