Quantcast
Channel: Crunchify
Viewing all articles
Browse latest Browse all 1037

How to redirect any incoming request from non-secure (HTTP) to secure (HTTPS) call?

$
0
0

htaccess-change-to-move-traffic-from-http-to-https

I love WordPress and all the customization which I do on my WordPress blog here. For Crunchify.com I’ve enabled HTTPS (SSL) some time back. Currently it’s disabled but we are planning to add it back after some more testing and analysis. Between we do have SSL enabled on business.crunchify.com site.

If you want to setup SSL on your blog then follow this tutorial. For new blog it’s mainly straightforward to enable HTTPS but sometimes it’s not that straight for old and very mature blog.

As you know, your blog links may be all of the places, like social media, other blogs, somebody’s bookmark, etc. Let’s take a look at below numbers under Links to Your Site section.

I’ve captured below image from Google Search Console.

Crunchify.com-Incoming-URLs-move-from-http-to-https

It’s nearly impossible to convert all of these links from http to https. Then how would you solve redirecting all above links to HTTPS in very simple way?

Here is a solution. Try to apply as per your need:

1. If you are running your blog on NGINX server then use below code

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

2. For Apache Server put below code to .htaccess file

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

And that’s it. All of your incoming request on port 80 (HTTP) will be permanently redirected to port 443 (HTTPS).

Do you want to do opposite mapping?

1. How to redirect all HTTPS request to HTTP?

Just put below code to .htaccess file on your server and you should be good. Now all of your https requests will be redirected to http.

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Have something to add to this article? Please chime in and join the conversation below.

The post How to redirect any incoming request from non-secure (HTTP) to secure (HTTPS) call? appeared first on Crunchify.
Author: App Shah

Viewing all articles
Browse latest Browse all 1037

Trending Articles