How to Redirect HTTP to HTTPS Using .htaccess

By Published On: December 28, 2019

Traditionally, all websites and web servers are configured by default to all HTTP traffic over port 80 (Check Network Protocols Standards). But HTTP is insecure and vulnerable to hackers’ attacks. So today we’ll configure your web-server to redirect HTTP to HTTPS using .htaccess

Because HTTP traffic is transferred as a plain text (not encrypted). So any hacker who can sniff traffic between server and client will see all traffic. like passwords, usernames, and credit card information.

Recently, most of the web browsers display an insecure warning like the below

HTTP Insecure Warning
HTTP Insecure Warning

Moreover, your website SEO rank will be affected strongly if your website is flagged as not secure.

So I’ll try to help you to turn your website from HTTP to HTTPS. S stands for secure.

1. Purchase Your SSL Certificate

the first step is to purchase an SSL certificate. Which helps you to encrypt all transferred traffic. And you can buy it for free from sslforfree.com if you have a personal or a simple blog website.

2. Redirect HTTP to HTTPS Using .htaccess

this step is valid for any website. You may be using WordPress, other CMS, Or custom web app.

  1. Login to cPanel or your web hosting panel.
  2. Files > File Manager > Document Root for:
  3. Now select the domain name you want to access or public_html if it’s your primary domain.
  4. Check “Show Hidden Files (dotfiles)”
  5. After a new tab or window opens, look for the .htaccess file.
  6. Edit the file
  7. “Save Changes” when done.
  8. Test your website to make sure it is done correctly. In case, there is an error, restore to the previous version and try again.

3. Redirect all Web Traffic

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

4. Redirect Specific Folder

RewriteEngine OnRewriteCond %{SERVER_PORT} 80RewriteCond %{REQUEST_URI} "/folder/subfolder"RewriteRule ^(.*)$ "https://www.yourdomain.com/folder/"$1 [R,L]

5. Use “Really Simple SSL” WordPress Plugin

If you want a simple and straightforward method to redirect HTTP to HTTPS on your WordPress site.

Thank you for reading!

Share this article

Written by : Ahmed Hesham AbdElHalim

Leave A Comment