IIS URL重写https规则忽略本地主机
我正在尝试编写URL重写规则以强制HTTPS连接。除非请求使用localhost(例如IIS URL重写https规则忽略本地主机,iis,rewrite,Iis,Rewrite,我正在尝试编写URL重写规则以强制HTTPS连接。除非请求使用localhost(例如http://localhost/mysite) 规则配置如下: <rule name="Redirect to https" enabled="true" stopProcessing="true"> <match url="(.*)" negate="false" /> <conditions trackAllCaptures="false">
http://localhost/mysite
)
规则配置如下:
<rule name="Redirect to https" enabled="true" stopProcessing="true">
<match url="(.*)" negate="false" />
<conditions trackAllCaptures="false">
<add input="{HTTPS}" pattern="^OFF$" />
<add input="{URL}" pattern="localhost" negate="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
</rule>
我还尝试使用^localhost和^localhost/(*)作为URL条件的模式,但没有任何帮助。
有人知道为什么这样做不起作用,以及这个问题的解决方案是什么吗?您的代码应该是这样的
<rule name="Redirect to https" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="off" />
<add input="{HTTP_HOST}" pattern="localhost" negate="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
</rule>
哪个版本的IIS?你可能想用这个更新你的问题。现在我在IIS8上使用它。但您已经提供了解决方案。谢谢。