Web.config 重定向到 http://www.example.com 到 https://example.com
Web.config Redirect to http://www.example.com to https://example.com
我想重定向 http://www.example.com, http://example.com or https://www.example.com to https://example.com。如何使用 web.config 文件执行此操作?
安装URL重写模块(默认不安装)。 http://www.iis.net/downloads/microsoft/url-rewrite
完成后,您可以在 system.webServer/rewrite/rules 下的 web.config 中设置规则部分。添加此规则:
<rule name="Redirect www to domain" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny" trackAllCaptures="false">
<add input="{HTTPS}" pattern="^OFF$" />
<add input="{HTTP_HOST}" pattern="^www.example.com" />
</conditions>
<action type="Redirect" url="https://example.com/{R:1}" />
</rule>
我想重定向 http://www.example.com, http://example.com or https://www.example.com to https://example.com。如何使用 web.config 文件执行此操作?
安装URL重写模块(默认不安装)。 http://www.iis.net/downloads/microsoft/url-rewrite
完成后,您可以在 system.webServer/rewrite/rules 下的 web.config 中设置规则部分。添加此规则:
<rule name="Redirect www to domain" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny" trackAllCaptures="false">
<add input="{HTTPS}" pattern="^OFF$" />
<add input="{HTTP_HOST}" pattern="^www.example.com" />
</conditions>
<action type="Redirect" url="https://example.com/{R:1}" />
</rule>