Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ihipop/a09b0ad253a007b71b8b702f5d37a3c7 to your computer and use it in GitHub Desktop.
Save ihipop/a09b0ad253a007b71b8b702f5d37a3c7 to your computer and use it in GitHub Desktop.
IIS7 配置web.config使用重定向来规范主机域名 自适应HTTP/HTTPS协议 ///// IIS7 web.config Redirct to a Canonical Host Name with correct HTTP/HTTPS scheme
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="WWW Redirect Right property" stopProcessing="true">
                    <match url=".*"/>
                    <conditions>
                        <add input="{HTTP_HOST}" pattern="^www\.xxx\.cn$" negate="true" />
                    </conditions>
                    <action type="Redirect" url="{MapSSL:{HTTPS}}www.xxx.cn/{R:0}" redirectType="Permanent"/>
                </rule>
            </rules>
            <rewriteMaps>
                <rewriteMap name="MapSSL" defaultValue="http://">
                    <add key="ON" value="https://" />
                    <add key="OFF" value="http://" />
                </rewriteMap>
            </rewriteMaps>
        </rewrite>
    </system.webServer>
</configuration>

Reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment