IIS URL重写https规则忽略localhost [英] IIS URL Rewrite https rule ignoring localhost
本文介绍了IIS URL重写https规则忽略localhost的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试编写URL重写规则来强制进行HTTPS连接。这应该总是发生,除非请求使用localhost(例如 http:// localhost / mysite
)。
I'm trying to write a URL rewrite rule to force a HTTPS connection. This should always happen except when a request is using localhost (e.g. 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的模式条件没有帮助。
有没有人知道为什么这不起作用以及该问题的解决方案应该是什么?
I also tried to use ^localhost and ^localhost/(.*) as a pattern for the URL condition with no help. Does anyone have an idea why this does not work and what a solution for this problem should be?
推荐答案
你的代码看起来应该是这样的
Your code should look like this instead
<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 URL重写https规则忽略localhost的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文