Are you thinking of securing your website with an SSL Certificate?

If Yes, then you are the right track. Google is running tests to check if sites use SSL or not in their search ranking algorithms.

In the case of No, then you must start considering getting SSL due to the following reasons:-

  1. Secure connection helps in building trust with the users.
  2. SSL certificate plays a vital role in improving your search engine rankings.

Don’t know where you can buy an SSL Certificate? Get your SSL Certificate From Here

Now that you have an SSL Certificate, the next step is to redirect HTTP to HTTPS for safety, accessibility or PCI compliance reasons. Before we move onto the redirecting process, you need to edit the .htaccess file.

If you have already done or know how to edit the .htaccess file, then you can directly skip to htaccess redirect to https steps.

Must Read: Different Types of SSL Certificates 

Steps to Edit .htaccess File

There are specific instructions in the .htaccess file that informs the server how to behave in particular cases and directly affects your site functionality. Two primary directives in a .htaccess file are Redirects and Rewriting URLs.

DIfferent ways to edit the .htaccess file are:-

  1. Edit the file on your computer and upload it to the server using FTP.
  2. Use “Edit” mode in the FTP program that allows you to edit a file remotely.
  3. Make use of a text editor and SSH to edit the file.
  4. Use the File Manager in cPanel to edit the file.

htaccess redirect to https

Editing .htaccess in cPanel File Manager

Note- Backup your website in case something goes wrong.

  1. Login to cPanel
  2. Files > File Manager > Document Root for:
  3. Now select the domain name you want to access
  4. Check “Show Hidden Files (dotfiles)”

htaccess redirect http to https

  1. Click “Go”
  2. After a new tab or window opens, look for the .htaccess file.
  3. Right click on the .htaccess file and click on “Code Edit” on the menu.
  4. A dialogue box may pop up asking about encoding. Click the “Edit” button to continue.
  5. Edit the file
  6. “Save Changes” when done.
  7. Test your website to make sure it is done correctly. In case, there is an error, restore to the previous version and try again.
  8. Once you are done, click “Close” to close the window.

Get Step by Step Guide to Install SSL Certificate here.

How to Redirect http to https In Apache?

How to Redirect http to https In Apache?

1. Redirect All Web Traffic

If you have existing code in your .htaccess, add the following:

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

2. Redirect Only a Specific Domain

For redirecting a specific domain to use HTTPS, add the following:

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

3. Redirect Only a Specific Folder

Redirecting to HTTPS in a particular folder, add the following:

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

Note: Replace “yourdomain” with your actual domain name wherever required. Also, in case of the folder, replace /folder with the real folder name.

How to do http to https redirect In Nginx?

Note- Take a backup of nginx.conf or default.conf file

  1. Login to Nginx web server
  2. Add return 301 https://$server_name$request_uri in server directive.
  3. Save the file.
  4. The last step is to restart your Nginx Web Server.

Phew! It’s done.


Think it was useful? Share this article to help them come on HTTPS 🙂

Services we offer:

  1. Managed Magento Hosting on Cloud.
  2. Managed WordPress Hosting for Growing Business.
  3. AWS Management | AWS Consulting Partners
  4. Managed DigitalOcean Cloud Hosting
  5. Managed Cloud Server India
  6. Dedicated Server India

Enquire now and join 1000+ businesses who have blitz scaled their websites by choosing ServerGuy as their hosting partner.

ServerGuy_icon_in_White

Grow with confidence backed by our fully Managed Hosting. Join 1000s of Brands & Agencies across the globe who trust us.