Tuesday, April 13, 2021

IIS - Create a from HTTP to HTTPS redirect

 1. Install the url rewrite module extension below.

https://www.iis.net/downloads/microsoft/url-rewrite


2. Then add this to the web.config inside <system.webServer>

  <rewrite>
            <rules>
                <rule name="HTTPS Redirect" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTPS}" pattern="^OFF$" />
                    </conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" 
                    appendQueryString="false" redirectType="Permanent" />
                </rule>
            </rules>
        </rewrite>

Make sure you have https bindings set and that the firewall accepts incoming on 80 and 443.

No comments:

Post a Comment