2014-10-06 62 views
10

我想写一个URL重写规则来强制HTTPS连接。除非请求使用本地主机(例如http://localhost/mysite),否则应始终发生。IIS URL重写https规则忽略本地主机

的规则配置如下:

<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> 

我还试图用^本地主机和本地主机^ /(.*),作为没有帮助的URL条件的模式。 有没有人有一个想法,为什么这不起作用,这个问题的解决方案应该是什么?

+0

哪个版本?你可能想用这个更新你的问题。 – kkuilla 2014-10-06 15:40:10

+0

现在我在IIS8上使用它。但是你已经提供了解决方案。非常感谢。 – 2014-10-06 16:43:00

回答

22

你的代码看起来应该像IIS的这个代替

<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> 
+1

你是男人!非常感谢! – 2014-10-06 16:42:14