Click here to Skip to main content
15,886,815 members
Articles / Hosted Services / WordPress
Tip/Trick

How to Redirect HTTP to HTTPS Automatically

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
10 Nov 2017CPOL3 min read 12.1K   2   2
If you want that your site always opens with SSL/ HTTPS only, then you need to redirect HTTP to HTTPS. There are several methods to do it. But in this tip, I share the easiest HTTPS redirection methods.

Sometimes, it is beneficial to redirect your users through SSL secure connection. If you are running an E-commerce website that collects sensitive information like credit card details, passwords, etc., then SSL is a must. On 6th August 2014, Google officially announced this as ranking signal. There are several reasons that you need to move your site to SSL/ HTTPS right away.

  • Google officially announced that “Now all the sites that are using SSL/ HTTPS will get a ranking boost on Google search results. This will be a huge boost, but however, HTTPS sites will rank higher than HTTP sites.
  • The main reason to use SSL is to keep the site secure. If any site collects important data, i.e., passwords, user details, credit card information, then those data can be hacked easily through an unsecured connection. But an SSL enabled site encrypts all the sensitive information and passes to the server. This way, all information remains safe.
  • Your customer trusts your site. Having an SSL on your site makes them sure that your website is protected and safe to provide sensitive data.

If you are running an E-commerce site, then you need a premium SSL which costs around $70. If you run a blog website or don’t collect credit card information, then you can easily use free SSL Certificate from Let’s Encrypt.

After installing SSL certificate, many times users have not been redirected to HTTPS automatically. So every time a user needs to type the full website address including HTTPS. For example, https://www.samplesite.com. This is quite annoying as most of the users don’t enter a website by typing the full address on their web browser. In this case, you can force SSL or redirect HTTP to HTTPS, so all the users will be automatically redirected through a secure connection.

There are many ways in which you can redirect HTTP to HTTPS and I am sharing those easiest methods that you can easily force SSL on your site.

Redirect HTTP to HTTPS through cPanel

If your web hosting company provides free SSL certificate, then you can install it directly from your cPanel. To do this, log in to your cPanel and go to security and from there, install Let’s Encrypt SSL certificate. It is a very simple method and it can be installed with just one click.

Redirect HTTP to HTTPS using Apache mod_rewrite

If your web server runs by Apache, then you can force SSL or redirect SSL using a .htaccess file. Add the following code to your site .htaccess file.

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

If you want to force SSL on a specific folder of your site, then add the following code to your site .htaccess file.

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

HTTPS Redirection in Nginx

If your web server is running Nginx, then you can easily redirect all HTTP traffic to HTTPS by adding the following code in your Nginx config file.

First, go to “/etc/nginx/nginx.conf” and add the following code:

server {
listen 80;
server_name domain.com www.domain.com;
return 301 https://domain.com$request_uri;
}

Don't forget to save it.

Using this method, your website will be accessible only SSL/ HTTPS connection. If you are getting an error or stuck on any step, please leave a comment below. I will be glad to help you.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
CEO WPMyWeb
India India
Jyoti Prakash Ray is the founder of WPMyWeb.com. He writes about Blogging, WordPress tutorials, Hosting, Affiliate marketing etc. He mostly spends times on blogging, reading books and cooking.

Comments and Discussions

 
QuestionRedirecting to HTTPS in Nginx Pin
ahill9931-Jul-19 9:54
ahill9931-Jul-19 9:54 
PraiseIIS redirect Pin
obermd13-Nov-17 9:41
obermd13-Nov-17 9:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.