【发布时间】:2014-01-23 17:27:30
【问题描述】:
我正在使用答案 given here 作为尝试将重写规则添加到我的 web.config 文件的基础。我希望它匹配任何未在 localhost 上运行的 url 以强制使用 https。
这是我现在拥有的:
<system.webServer>
<rewrite> <!-- force https - https://stackoverflow.com/a/15119044/51 -->
<rules>
<rule name="Redirect HTTP to HTTPS" stopProcessing="true">
<match url="^((?!localhost).)*$"/>
<conditions>
<add input="{HTTPS}" pattern="^OFF$"/>
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther"/>
</rule>
</rules>
</rewrite>
</system.webServer>
我正在尝试使用negative lookaround,以便仅匹配不包含“localhost”的 url。但这不起作用。
那么应该如何设置这个规则才能只重写非本地 url 的呢?
【问题讨论】:
标签: regex asp.net-mvc url-rewriting web-config