Admin-Ahead Community

Windows => General Windows => Topic started by: sibij on April 17, 2018, 08:06:51 am

Title: How to redirect Website from HTTP to HTTPS in windows hosting with IIS?
Post by: sibij on April 17, 2018, 08:06:51 am
How to redirect Website from HTTP to HTTPS in windows hosting with IIS?  ::)


Be sure that the SSL Certificate is properly installed on your domain, and the website is resolving on your domain like https://example.com
    Create a web.config file under the site’s directory and add the following lines to it. In case there already exists a web.config in your site’s directory, carefully edit it to add these lines:
Code: [Select]
<?xml version="1.0"?>
    <configuration>
      <system.webServer>
         <rewrite>
                   <rules>
                   <rule name="Redirect to HTTPS" stopProcessing="true">
                   <match url="(.*)" />
                        <conditions>
                        <add input="{HTTPS}" pattern="^OFF$" />
                        </conditions>
                   <action type="Redirect" url="https://example.com/{R:1}" redirectType="Permanent" />
                   </rule>
                   </rules>
         </rewrite>
      </system.webServer>
    </configuration>

    example.com needs to be replaced by the Domain Name for which the SSL Certificate is issued. 8)