asp.net IIS URL重定向 设置,先到微软官网下载URL Rewrite
https://www.iis.net/downloads/microsoft/url-rewrite
根据自己服务的版本,下载对应的URL Rewrite 安装包,Chinese Simplified: x86 installer / x64 installer
本人在安装后,查看网站信息中,并不没有看到 URL Rewrite 这个模块,一度怀疑自己装错了,然后网上说要先停止IIS服务器管理器,不是停止网站或服务器,要把IIS管理器先关掉这样才行,然后再安装URL Rewrites安装包,果然有效。
下面就可以直接配制URL重新规则 ,下面是将域名重定向操作示例,
<configuration>
<system.web>
<compilation targetFramework="4.0" />
<customErrors mode="Off" />
</system.web>
<system.webServer>
<rewrite>
<rules>
<rule name="301Redirect" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^abc.com$" />
</conditions>
<action type="Redirect" url="http://www.abc.com/{R:0}" redirectType="Permanent" />
</rule>
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>