【发布时间】:2023-03-14 15:40:02
【问题描述】:
我的 ASP.NET MVC 5 项目的web.config 中有以下重写规则:
<rule name="Redirect example.com to www.example.com and enforce https" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^[^www]" />
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://www.example.com/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
该规则将非 www 重定向到 www 并将 http 重定向到 https(因此 http://example.com/hey 之类的东西将重定向到 https://www.example.com/hey)并且工作正常。然而,它也适用于localhost,我似乎无法解决它——我尝试了包含| 的否定规则和正则表达式,但似乎无法找到正确的组合。我是不是走错了路?
【问题讨论】:
标签: asp.net asp.net-mvc iis url-rewriting web-config