繁体   English   中英

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

[英]IIS rewrite rule to redirect https to http not working

这里有很多关于将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>

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

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

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>

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

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

你的重定向仍然是http

url="http://www.example.com/{R:1}"

您可以按照以下说明操作: 单击此处

附加信息: 这里

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM