【问题标题】:URL Rewrite http to https and let's encryptURL 将 http 重写为 https 并加密
【发布时间】:2020-10-16 04:29:16
【问题描述】:

我正在尝试在我的 IIS 上设置 URL 重写,以便它处理 http 并进行加密。我的目标如下

1) 到 http://example.comhttp://www.example.comhttps://www.example.com 的所有流量都应重定向 (301) 到 https://example.com

2) 应保留任何子页面和查询字符串,以便 http://www.example.com/whatever/login.aspx?username=blabla 变为 https://example.com/whatever/login.aspx?username=blabla

3) 不应重定向对http://example.com/.well-known/acme-challenge/* 和http://www.example.com/.well-known/acme-challenge/* 的所有请求(其中“*”可以是任何子页面和查询字符串)

这就像我什么都试过了,但我无法让它发挥作用。

【问题讨论】:

    标签: iis url-rewriting lets-encrypt url-rewrite-module


    【解决方案1】:

    您可以通过两条规则做到这一点。第一个将重定向到 https,第二个将更改域。您需要将您的 URL .well-known/acme-challenge/ 添加为具有“否定”属性的条件

        <rule name="CanonicalHostNameRule">
            <match url="(.*)" />
            <conditions logicalGrouping="MatchAll">>
                <add input="{HTTP_HOST}" pattern="^www.example\.com$" />
                <add input="{REQUEST_URI}" pattern="^/.well-known/acme-challenge" negate="true" />
            </conditions>
            <action type="Redirect" url="https://example.com/{R:1}" />
        </rule>
        <rule name="Redirect to https">
            <match url="(.*)" />
            <conditions logicalGrouping="MatchAll">
                <add input="{HTTPS}" pattern="off" />
                <add input="{REQUEST_URI}" pattern="^/.well-known/acme-challenge" negate="true" />
            </conditions>
            <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
        </rule>
    

    【讨论】:

    • 你太棒了——我现在一直在和这个作斗争:)
    猜你喜欢
    • 2014-09-20
    • 2011-06-02
    • 2017-11-06
    • 2018-07-05
    • 1970-01-01
    • 1970-01-01
    • 2014-07-18
    • 2021-12-28
    • 2010-12-04
    相关资源
    最近更新 更多