Redirect Website from HTTP to HTTPS

In this Post, I have provided code to redirect website from HTTP to HTTPS for PHP and for .NET Websites. Do install SSL on your website before applying redirection code or else you will face error. If you don’t have SSL then, purchase it , install SSL then use redirection code

Now, without wasting time let’s start with the steps to redirect.

HTTP to HTTPS for PHP

Apache

Use the code below in your .htaccess file to automatically redirect visitors to https.

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

NOTE: .htaccess file can be hidden in some of the hosting and you need to unhide and add above code to it. If .htaccess file is not present then create one and above code.

Nginx

Use below code configuration file of website to redirect website to https on Nginx based server.

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

 

HTTP to HTTPS for .NET

Use the code below in your web.config file inside <configuration> to automatically redirect visitors to https.

<system.webServer>
<rewrite>
<rules>
<rule name=”HTTP to HTTPS redirect” stopProcessing=”true”>
<match url=”(.*)” />
<conditions>
<add input=”{HTTPS}” pattern=”off” ignoreCase=”true” />
</conditions>
<action type=”Redirect” redirectType=”Permanent” url=”https://{HTTP_HOST}/{R:1}” />
</rule>
</rules>
</rewrite>
</system.webServer>

That's all you need to redirect your website from http to https.

If this post was helpfull, Do like and share.
Thanks.

 

Please follow and like us:
error

One thought on “Redirect Website from HTTP to HTTPS

  • April 30, 2019 at 3:39 AM
    Permalink

    Hi, I do believe this is a great site. I stumbledupon it
    😉 I’m going to return yet again since i have saved as
    a favorite it. Money and freedom is the greatest way to change,
    may you be rich and continue to guide others.

    Reply

Leave a Reply

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