Support Center » Knowledgebase » Unix Tips » How to redirect non ssl to ssl (http to https)

How to redirect non ssl to ssl (http to https)



For Unix/Apache

For Unix based web sites running under Apache, you may want to allow only SSL connections to pass through and automatically redirect people to your SSL site. This is done by detecting if they are connected on the non SSL and redirecting them to https://

This can be done by adding a .htaccess file in your web root directory with the following directive inside. If there is already a .htaccess file, you can add the content in the existing file either at the beginning or at the end of the file.

<IfModule mod_rewrite.c> RewriteEngine on RewriteBase / RewriteCond %{HTTPS} !on RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [R] </IfModule>



For Windows / IIS 7 and above

Create a file called web.config and place it in your web site root directory.

Code:
<?xml version="1.0" encoding="UTF-8"?>
<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="Found" url="https://{HTTP_HOST}/{R:1}" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

Whenever someone types http://www.yoursite.com/something, they will be redirected to https://www.yoursite.com/something



Article Details
Article ID: 93
Created On: 01 Nov 2004 06:00 AM
 Back
 Login [Lost Password] 
Email:
Password:
Remember Me:
Please note that the login and password to the support area is NOT the same as your hosting control panel login and password
 
 Search
 Article Options
Home | Register | Submit a Ticket | Knowledgebase | Downloads | Control Panel User's Guide | Server Status
Language: