用于重写URL的Web.config规则始终从https重定向到http

时间:2017-06-07 23:06:42

标签: php azure iis web-config nette

我遇到了web.config和强制SSL的问题。我有一个重写URL的规则,因为Nette PHP站点是托管的。

<rule name="Rewrite Admin" stopProcessing="true">
                  <match url="^admin/(.*)" ignoreCase="true"/>
                  <conditions logicalGrouping="MatchAll">
                      <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                      <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />    
                  </conditions>
                  <action type="Rewrite" url="/admin/index.php" />
               </rule>

如果我在网址中使用 https ,请求始终会重定向到http。 (https://example.com/admin - &gt; example.com/admin)。当我在下面对所有请求使用SSL强制规则时,会发生错误(重定向太多)。 (在web.config中有2个规则)

<rule name="Redirect to https">
        <match url="(.*)"/>
        <conditions>
          <add input="{HTTPS}" pattern="Off"/>
          <add input="{REQUEST_METHOD}" pattern="^get$|^head$" />
            <add input="{REQUEST_URI}" pattern="^/(node)" negate="true" />
            <add input="{REQUEST_URI}" pattern="^/(cbre)" negate="true" />
        </conditions>
        <action type="Redirect" url="https://{HTTP_HOST}/{R:1}"/>
      </rule>

如何强制ssl为动作类型“重写”?

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

我带了你的rule配置但无法重现该问题。因此,要将HTTP流量重定向到HTTPS,我建议您通过Kudu安装名为Redirect HTTP to HTTPS的网站扩展程序。

  1. 打开浏览器并访问:

    https://<your-app-name>.scm.azurewebsites.net/SiteExtensions/#gallery
    
  2. 在搜索框中输入“重定向”,然后点击搜索按钮。

    enter image description here

  3. 选择Redirect HTTP to HTTPS,然后点击添加按钮。

  4. 对话框打开时,点击安装按钮。
  5. 点击重新启动网站按钮,使其可用。
相关问题