Redirect HTTP to HTTPS in 4 Simple Steps

Redirect HTTP to HTTPS in 4 Simple Steps
Last updated Nov 10, 2020

Managed hosting provider if you’re not yet on HTTPS, the browser is going to through a “Not Secure” warning on your website. For compliance purposes, you need to have an SSL-encrypted connection. Once, you have installed SSL, it is crucial to redirect HTTP to HTTPS.

What is HTTP to HTTPS Redirect?

Earlier, the most common redirect concern was to properly redirect the www version of the site to the non-www site, or vice-versa. However, with the introduction of SSL certificates, HTTP to HTTPS redirect has taken over.

For example, consider the Webscoot.io website. Our canonical address is https://webscoot.io. However, a user can connect to our website in 4 ways:

SourceType
https://webscoot.ioHTTP + no-www
https://webscoot.ioHTTPS + no-www
https://webscoot.ioHTTP + www
https://webscoot.ioHTTPS + www

In this article, we’ll see how to redirect HTTP to HTTPS connection with www:

1. Redirect HTTP to HTTPS in Apache

Before we get to redirecting HTTP to HTTPS using .htaccess file, here’s how you can edit the .htaccess file:

How to edit a .htaccess file:

To force your traffic to HTTPS, edit the codes in the .htacess file. If you already know this step, you can move to the redirection part.
There are instructions in the .htaccess file that describe the server how to perform in certain scenarios. This affects how your website functions.

The most common instructions are:
1. Rewriting URLs
2. Redirects

3 Ways to edit a .htaccess file:

  • Edit the file on your PC and upload it to the server via FTP.
  • Use “Edit” mode in FTP program allows you to edit a file remotely.
  • Use SSH and a text editor to edit files.

1.1. Redirecting all web traffic

To redirect all traffic to HTTPS, add the following to the existing code:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://webscoot.io/$1 [R=301,L]

1.2. Redirecting a specific domain

To redirect a specific site to use HTTPS:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?webscoot.com
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://webscoot.io/$1 [R=301,L]

1.3. Redirecting specific folder

To redirect HTTP to HTTPS on a specific folder, add the following code:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} folder
RewriteRule ^(.*)$ https://webscoot.io/folder/$1 [R=301,L]

1.4. Force redirect to 301

To force traffic to HTTPS, use the following code:

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

Note:
1. Replace “webscoot” with your domain name wherever required.
2. Replace /folder with the actual folder name.

2. Redirect HTTP to HTTPS in Nginx

Nginx is the fastest growing web server. We use Nginx in our server stacks for optimized performances.

2.1. Redirect all traffic to HTTPS

server {
     listen 80 default_server;
server_name _;

return 301 https://$host$request_uri;
}

2.2. Redirect specific sites to HTTPS

server {
    listen 80;

    server_name webscoot.com;
    return 301 https://webscoot.io$request_uri;
}

Conclusion

Almost all websites are on HTTPS now. Share this article to bring the rest of the websites on an encrypted connection. If your web host is not taking care of your website security, move to a Managed hosting provider to keep your website security bulletproof.

  •  
  •  
  •  
  •  
  •  

Frequently Asked Questions About Website Speed Test

Q1) Is redirect HTTP to HTTPS easy?

Reach out to our support team, you can easily redirect all of your HTTP traffic to HTTPS.

Q2) Is it possible to redirect HTTP to HTTPS using htaccess?

Yes, it is possible to redirect using the htacess file by using a code snippet.

 

Q3) How to redirect HTTP to HTTPS Nginx?

Configuring a separate server block to handle each version of the site is the best way to redirect HTTP to HTTPS with Nginx.

Q4) How to redirect HTTP to HTTPS Apache?

Apache allows you to create simple single-page redirects by using The “Redirect” directive is part of the “mod_alias” module.

6 Comments

  1. Vivek

    Very simple guide to redirect http to https. helped me!

    Reply
  2. Phillipp

    Can you tell me what platform are you utilizing on this website?

    Reply
    • Sakshi Behl

      Hi Phillipp,

      We use WordPress. 🙂

      Reply
  3. Steve

    I installed SSL, and then I tried to redirect http to https using htaccess as you showed in this article and it worked well, thank you so much you saved my time.

    Reply
  4. Shailender Sharma

    You have worked hard on your website. You have helped us a lot through this post, we hope that you will continue to write such informative posts in the future also. Which will benefit many people.

    Reply

Submit a Comment

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