IIS重写规则将https重定向到http无法正常工作

Gav*_*vin 4 asp.net iis web-config url-rewriting

这里有很多关于将http重定向到https的问题,所以我认为很容易扭转这个过程.但是,我尝试过的一切都没有奏效.

我正在尝试将规则与我的规范主机名规则相结合(这是第一条规则,在重写规则的顶部):

<rule name="CanonicalHostName" stopProcessing="true">
  <match url="(.*)" />
  <conditions logicalGrouping="MatchAny">
    <add input="{HTTPS}" pattern="^ON$" />
    <add input="{HTTP_HOST}" negate="true" pattern="^www\.example\.com|example-staging\.azurewebsites\.net$" />
  </conditions>
  <action type="Redirect" url="http://www.example.com/{R:1}" redirectType="Permanent" />
</rule>
Run Code Online (Sandbox Code Playgroud)

该网站托管在Azure上,DNS与CloudFlare一起使用,如果这有任何区别,我相信它不应该.

任何想法我做错了/可能会阻止https到http规则的一部分工作?(主机名部分工作正常)

Ash*_*way 5

CloudFlare的

您似乎无法从SSL重定向的原因是因为您使用的是CloudFlare.CloudFlare至少使用灵活的SSL.这意味着最终用户,浏览器显示SSL锁定,但您的服务器不需要SSL.请参阅此处的文档:https://www.cloudflare.com/ssl

如果没有CloudFlare,以下示例应该可以正常工作.

没有CloudFlare

以下规则应该有效.如果你愿意,你仍然可以添加你的否定.

<rule name="HTTPS to HTTP redirect" stopProcessing="true">
    <match url="(.*)" />
    <conditions>
        <add input="{HTTPS}" pattern="on" ignoreCase="true" />
    </conditions>
    <action type="Redirect" redirectType="Found" url="http://{HTTP_HOST}/{R:1}" />
</rule>
Run Code Online (Sandbox Code Playgroud)

我的工作演示站点的完全重写部分.

<rewrite>
    <rules>
        <rule name="CanonicalHostNameRule1">
            <match url="(.*)" />
            <conditions>
                <add input="{HTTP_HOST}" pattern="^www\.ashleymedway\.com$" negate="true" />
            </conditions>
            <action type="Redirect" url="http://www.ashleymedway.com/{R:1}" />
        </rule>
        <rule name="HTTPS to HTTP redirect" stopProcessing="true">
            <match url="(.*)" />
            <conditions>
                <add input="{HTTPS}" pattern="on" />
            </conditions>
            <action type="Redirect" url="http://{HTTP_HOST}/{R:1}" redirectType="Found" />
        </rule>
    </rules>
</rewrite>
Run Code Online (Sandbox Code Playgroud)