Frequently Asked Questions

Redirect HTTP to HTTPS Automatically

Print this Article
Last Updated: July 21, 2015 1:51 PM

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 your communications are encrypted.

How you do that depends on what type of hosting account you have (more info).

Windows

You'll need to either create or modify your hosting account's web.config file. If you need to create one, you can use your control panel's file manager (Web & Classic / Plesk). To populate the file, see Microsoft's article How To Create the Web.config File for an ASP.NET Application.

In the web.config file you create, you also need to add rewrite and rules tags, as well as close them, in the system.webServer section.

To Automatically Redirect Visitors to HTTPS

  1. Using your hosting account's editor (Web & Classic / Plesk), open your account's web.config file.
  2. In the rules section, add the following rule:
    <rule name="HTTP to HTTPS redirect" stopProcessing="true"> <match url="MS_124923.*)" /> <conditions> <add input="{HTTPS}" pattern="off" ignoreCase="true" /> </conditions> <action type="Redirect" redirectType="Found" url="../https/{http_host}/7BR/MS_124924.html" /> </rule>

    For example, if your web.config file contained no other rules or content, it would look like this:
    <configuration> <system.webServer> <rewrite> <rules> <rule name="HTTP to HTTPS redirect" stopProcessing="true"> <match url="MS_124923.*)" /> <conditions> <add input="{HTTPS}" pattern="off" ignoreCase="true" /> </conditions> <action type="Redirect" redirectType="Found" url="../https/{http_host}/7BR/MS_124924.html" /> </rule> </rules> </rewrite> </system.webServer> </configuration>
  3. Save your changes.

Linux

You'll need to either create or modify your hosting account's .htaccess file. If you need to create one, you can use your control panel's file manager (Web & Classic / cPanel).

Add the following code to the .htaccess file:

RewriteEngine On
RewriteCond %{SERVER_PORT} !=443
RewriteCond %{HTTP_HOST} ^(www\.)?your domain name\.com$ [NC]
RewriteRule ^$ https://www.your domain name.com/%{REQUEST_URI} [R,L]

Where your domain name is your website's domain name. You will need to replace .com with your domain name's TLD.

You can also redirect specific folders off of your domain name by replacing the last line of the code above with:

RewriteRule ^ https://[your domain name]/[directory name]%{REQUEST_URI} [R,L]

Where [directory name] is the directory you want to use.

Important: If you have existing code in your .htacess, add this above where there are already rules with a similar starting prefix.