[英]IIS URL Rewrite https rule ignoring localhost
I'm trying to write a URL rewrite rule to force a HTTPS connection. 我正在尝试编写URL重写规则来强制HTTPS连接。 This should always happen except when a request is using localhost (eg
http://localhost/mysite
). 这应该总是发生,除非请求使用localhost(例如
http://localhost/mysite
)。
The rule is configured as following: 规则配置如下:
<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>
I also tried to use ^localhost and ^localhost/(.*) as a pattern for the URL condition with no help. 我也尝试使用^ localhost和^ localhost /(.*)作为URL条件的模式,没有任何帮助。 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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.