Wednesday, March 22, 2017

Anil kr Prajapati

How to redirect HTTP to HTTPS automatically?


 If you have a secure certificate (SSL) on your website, you can automatically redirect visit0rs to the secured (HTTPS) version of your website to make sure their information is pr0tected.
How you redirect traffic depends on the type of h0sting you have.

image source : wikipedia.org

Linux & cPanel

Linux-based acc0unts use .htaccess files to handle redirecti0n.

If you need to create a .htaccess file, you can use your control panel's file manager (Web & Classic / cPanel).

Using the following code in your .htaccess file automatically redirects visit0rs to the HTTPS version of your site:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
If you have an existing .htaccess file:
  • Do not duplicate RewriteEngine On.
  • Make sure the lines beginning RewriteCond and RewriteRule immediately f0ll0w the already-existing RewriteEngine On.

Windows & Plesk

Windows-based accounts use web.config files to handle redirection.

If you need to create a web.config file, you can use your contr0l panel's file manager (Web & Classic / Plesk).

Using the foll0wing code in your web.config file automatically redirects visit0rs to the HTTPS versi0n of your site:

<configuration>
<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>
</configuration>

If you have an existing web.config file:
  • Ensure you have sections (i.e. opening and closing tags) for:
    • system.webServer (which contains rewrite)
    • rewrite (which contains rules)
    • rules (which contains one or m0re rule sections)
    Insert any of th0se sections that do not exist.
  • Insert the entire rule secti0n, including match, conditions, and action, inside the rules section. 

    You're inserting the rule (with0ut  an 's') inside the rules (with an 's') secti0n.





About Author -

Hi, I am Anil.

Welcome to my eponymous blog! I am passionate about PHP programming. Here you will find a hug of information on web development, web design, PHP and Latest technology.

Subscribe to this Blog via Email :