【问题标题】:http to https redirect - iis8.5 url rewrite 2.0 redirect rule not workinghttp 到 https 重定向 - iis8.5 url rewrite 2.0 重定向规则不起作用
【发布时间】:2017-11-19 17:02:03
【问题描述】:

我很难让下面的重定向规则起作用...

<rules>
<rule name="Relative Path Rewrite" stopProcessing="false">
  <match url=".*" />
  <conditions logicalGrouping="MatchAll">
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    <add input="{REQUEST_URI}" pattern="^/$" negate="true" />
  </conditions>
  <action type="Rewrite" url="/" />
</rule>
<rule name="Ssl Redirect" stopProcessing="false">
    <match url="(.*)" />
    <conditions>
        <add input="{HTTPS}" pattern="^OFF$" />
    </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
</rules>

问题如下...

如果我输入 http://mywebsite.com 它会重定向到 https://mywebsite.com 没问题。

但是,如果我输入http://mywebsite.com/faq,它会重定向到https://mywebsite.com 而不是https://mywebsite.com/faq,我不知道为什么?它似乎忽略了来自我的比赛的“{R:1}”反向引用,它应该是“常见问题解答”

我已经为此奋斗了一段时间,任何关于这里发生的事情的想法都会很棒。

一些额外的信息是,我正在托管一个应用此规则的 Angular 4.0 网站...

【问题讨论】:

  • 由于这条规则Relative Path Rewrite而出现问题。此规则中的条件:重定向所有内容,不是filedirectory 和URL 不是/。此规则将您从http://mywebsite.com/faq 重定向到http://mywebsite.com,然后从http://mywebsite.com 重定向到https://mywebsite.com

标签: iis url-rewriting url-redirection iis-8.5


【解决方案1】:

颠倒规则奏效了。

<rewrite>
 <rules>
  <rule name="Ssl Redirect" stopProcessing="false">
   <match url="(.*)" />
   <conditions>
    <add input="{HTTPS}" pattern="^OFF$" />
   </conditions>
   <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
  </rule>
  <rule name="Relative Path Rewrite" stopProcessing="false">
   <match url=".*" />
   <conditions logicalGrouping="MatchAll">
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    <add input="{REQUEST_URI}" pattern="^/$" negate="true" />
   </conditions>
   <action type="Rewrite" url="/" />
  </rule>          
 </rules>
</rewrite>

【讨论】:

    猜你喜欢
    • 2015-08-10
    • 2013-06-02
    • 2018-07-25
    • 2018-02-13
    • 1970-01-01
    • 2014-03-10
    • 2018-06-11
    • 2015-07-28
    • 2018-01-18
    相关资源
    最近更新 更多