Redirecting HTTP to HTTPS in .htaccess: Migration Guide

1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 5.00 out of 5)
Loading...

If you are reading this article, we can safely assume that you have already purchased an SSL certificate and looking forward to installing it. If you are still struggling in choosing the right SSL for your website, check out this article to understand the different SSL types and select the best-suited SSL with cost-efficient options.

Secure a WordPress Website with An SSL Certificate – Save 79%

Save 79% on a highly trusted Positive SSL, an ideal solution for WordPress CMS websites. It includes unlimited server licenses, reissuances, 256-bit encryption, and more.

Shop for Positive SSL and Save 79%

If you are looking for help redirecting HTTP to HTTPS on a WordPress site, consider our expert guide on How to Install An SSL Certificate on WordPress.

HTTP to HTTPS Redirection Guide with .htaccess

Locate .htaccess in cPanel File Manager

  • Go to cPanel
  • Click on File Manager under ‘Files.’
Files Option in cPanel
  • Select the option for Document Root for. Select the domain name from the drop-down menu. OR click on ‘Settings’ on the upper right side of the page if you have only one website.
  • Locate the .htaccess file
  • The .htaccess file is always hidden. So, check “Show Hidden Files (dotfiles)”
Preference Option in cPanel
  • Right-click on the .htaccess file and click on Edit
  • A dialogue box will pop up. Click on Edit again.
Edit Option in cPanel
Edit Option in cPanel for htaccess file

Before editing the code, there are a few things you should take into consideration:

  • Your .htaccess file must be stored in the website’s root folder or in the same folder where your site is located.
  • Search for the word RewriteEngine On in .htaccess file to avoid repetition. If RewriteEngine On is already written in the .htaccess file, add the below code immediately after it (don’t duplicate the RewriteEngine On line)
  • Type your own domain name in place of yoursite.com

.htaccess Code for HTTP to HTTPS Migration Without WWW

If you want your website’s non-www version to run on HTTPS (i.e., HTTPS://yoursite.com), add these lies in the .htaccess file:

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

.htaccess Code for HTTP to HTTPS Migration for WWW Version

If you are redirecting the WWW version of your domain to HTTPS (i.e., HTTPS://www.yoursite.com), add the below code to the .htaccess file

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.yoursite.com [NC]
RewriteRule ^ HTTPS://www.yoursite.com %{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTP:X-Forwarded-Proto} !HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^ HTTPS://yoursite.com %{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Redirect All Web Traffic from HTTP to HTTPS

If you want to redirect all web traffic to HTTPS (instead of redirecting to a specific site/webpage/folder), insert these codes.

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

Redirect a Particular Domain from HTTP to HTTPS

If you have multiple domains and want to redirect only a specific domain from HTTP to HTTPS, insert following codes.

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

Redirect Only a Specific Folder (webpage) to HTTPS

For some reasons, people choose to keep only some webpages on HTTPS, while keeping other pages on HTTP. To Redirect a specific folder/webpage to HTTPS, write following code:

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

11 thoughts on “Redirecting HTTP to HTTPS in .htaccess: Migration Guide

  1. Nice post. I learn something more challenging on different blogs everyday. It will always be stimulating to read content from other writers and practice a little something from their store. I’d prefer to use some with the content on my blog whether you don’t mind. Natually I’ll give you a link on your web blog. Thanks for sharing.

  2. You made some respectable factors there. I regarded on the internet for the problem and located most people will associate with with your website.

  3. I found your blog website on google and test a couple of of your early posts. Proceed to maintain up the excellent operate. I just extra up your RSS feed to my MSN News Reader. Searching for forward to studying extra from you later on!…

  4. I haven¦t checked in here for a while since I thought it was getting boring, but the last few posts are great quality so I guess I¦ll add you back to my daily bloglist. You deserve it my friend 🙂

  5. The next time I read a blog, I hope that it doesnt disappoint me as much as this one. I mean, I know it was my choice to read, but I actually thought youd have something interesting to say. All I hear is a bunch of whining about something that you could fix if you werent too busy looking for attention.

Leave a Reply

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