Have you recently installed an SSL Certificate on your site?

After successful installation of SSL, you need to redirect HTTP To HTTPS. The first step involves editing of .htaccess file. You can do it via FTP or cPanel File Manager. The second step involves htaccess redirect to https in Apache or NGINX.

There are mainly 2 reasons why you should secure your website with an SSL certificate.

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

Steps to redirect http to https htaccess are given below:-

  1. Editing .htaccess file via FTP
  2. Editing .htaccess file via cPanel File Manager
  3. Redirect http to https in Apache
  4. Redirect http to https in NGINX

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.

Editing .htaccess via FTP

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

 

htaccess redirect to https

 

Editing .htaccess in cPanel File Manager

Note- Backup your website in case something goes wrong.

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

 

Edit .htaccess in cPanel

 

  • Click “Go”
  • After a new tab or window opens, look for the .htaccess file.
  • Right-click on the .htaccess file and click on “Code Edit” on the menu.
  • A dialogue box may pop up asking about encoding. Click the “Edit” button to continue.
  • Edit the file.
  • “Save Changes” when done.
  • Test your website to make sure it is done correctly. In case, there is an error, restore to the previous version and try again.
  • 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:

Services we offer: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?

  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.

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

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.

Was this post helpful?

Share This