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 或 https:// www。 example.com https://example.com 。如何使用web.config文件执行此操作?
I want to redirect http://www.example.com, http://example.com or https://www.example.com to https://example.com. How do I do this with a web.config file?
推荐答案
安装URL重写模块(默认情况下不安装) )。 http://www.iis.net/downloads/microsoft/url-rewrite
Install the URL Rewrite module (it doesn't install by default). http://www.iis.net/downloads/microsoft/url-rewrite
完成后,您可以在system.webServer / rewrite / rules下的web.config中设置规则部分。添加此规则:
Once you have that, you can set up a rules section in your web.config under system.webServer/rewrite/rules. Add this rule:
<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>
这篇关于Web.config重定向到http://www.example.com到https://example.com的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!