In this tutorial we will show you How you can Redirect Website from HTTP to HTTPS using .htaccess. The easiest way to redirect a website running on http to https is by using htaccess. No matter what CMS you are using .htaccess can help you to redirect any http site to https.

Why SSL is needed for your website?

There are a lot of reasons why you should move to Https. The best part it helps indirectly in SEO, also it gives your users a trust with that padlock. It ensures that it is protecting them with hackers and phishing attacks. You can safeguard customer’s data and also you can secure the transactions by using SSL certificate.

How to redirect HTTP to HTTPS with .htaccess

First of all you have to install SSL certificate for using redirection. We will consider that you already have SSL installed on your server.

Now open you cPanel or file manager or FTP and find the .htaccess file and edit it.

You have to add any one of the following code in your .htaccess file depending on your requirement.

Option 1. Force Redirect all web traffic to HTTPS

To redirect all the web traffic you are getting, just add the 3 lines given below in your .htaccess file.

Make sure to replace domain.com with your own domain.

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.domain.com/$1 [R,L]

Option 2. Redirect a specific domain to HTTPS

To redirect only a singe domain, just add the 4 lines given below in your .htaccess file.

Make sure to replace domain.com with your own domain.

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^domain\\.com [NC] 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.domain.com/$1 [R,L]

That’s all you had to do, now clear your browser data and see the magic.

If you are using Cloudflare on your website then you don’t have to edit the .htaccess file at all, read the guide given below to redirect HTTP to HTTPS using cloudflare.

Bro Guide: How to Install Free Cloudflare SSL with WordPress.

Conclusion

This is how you can redirect all or some of your web server’s traffic by editing your .htaccess file. Let us know if you are facing any issues in the comment section. If you are under Host it Bro network, you can always open a support ticket as our Managed Web Hosting provides support for everything you need.

Previous ArticleNext Article

Leave a Reply

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