How to Redirect HTTP to HTTPS automatically

If you have a secure certificate (SSL) on your website, you can automatically redirect visitors to the secured (HTTPS) version of your website to make sure their information is protected.

Depending on your hosting plan (Windows/Linux) follow these guidelines for secure:

Linux & cPanel
Linux-based accounts use .htaccess files to handle redirection.

Note: 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 visitors 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 follow the already-existing RewriteEngine On.

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

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

Using the following code in your web.config file automatically redirects visitors to the HTTPS version 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 more rule sections)
  • Insert any of those sections that do not exist
  • Insert the entire rule section, including match, conditions, and action, inside the rules section
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How Do I Redirect HTTP to HTTPS Automatically?

Redirect http To https Automatically: To redirect http to https automatically just add below...

Mixing secure and insecure content on a web page

Problem When visitors to your web site request a page using a...

What is SSL / Secure Certificate?

What is SSL? SSL and Secure Certificates provide security for your website by encrypting...

Auto SSL from cPanel is not installing certificate on domain when AutoSSL is run

When you run AutoSSL it does not activate SSL on the domain and the domain gives SSL certificate...

Windows 2008 Unable to export private key (.pfx) after installing new cert on IIS 7

In order to get the Private Key associated with certificate, we need to follow the steps below on...