【问题标题】:URL Rewrite Module 2.1 redirection http to https not workingURL 重写模块 2.1 重定向 http 到 https 不工作
【发布时间】:2023-02-09 17:58:00
【问题描述】:

他们更改了 url 重写模块版本(URL 重写模块 2.1),现在从 http 到 https 的重定向不起作用。

有没有人遇到过同样的问题?

应用:角度

系统:Windows Server IIS 10

这是 web.config 文件(它适用于最早版本的 URL 重写:urlrewrite2.exe)

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <security>
            <requestFiltering>
                <fileExtensions applyToWebDAV="false">
                    <add fileExtension=".pdf" allowed="true" />
                </fileExtensions>
            </requestFiltering>
        </security>
        <directoryBrowse enabled="true" />
        <httpProtocol>
            <customHeaders>
                <add name="Access-Control-Allow-Credentials" value="true" />
                <add name="Access-Control-Allow-Headers" value="Content-Type" />
                <add name="Access-Control-Allow-Methods" value="GET,POST,PUT,DELETE,OPTIONS" />
                <add name="Access-Control-Allow-Origin" value="*" />
            </customHeaders>
        </httpProtocol>
        <rewrite>
            <rules>
                <rule name="redirect" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTPS}" pattern="^OFF$" />
                    </conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

谢谢。

【问题讨论】:

  • 我发现您的 RewriteRule 适用于 URL Rewrite 2.1。我建议执行一次 IIS 重置并查看它是否开始工作。如果问题仍然存在,请尝试检查失败请求跟踪日志以了解问题。如果有任何错误消息/屏幕截图,您可以分享。
  • @Deepak-MSFT 我重置了,还是不行
  • @Deepak-MSFT 我发现了问题,当我将端口更改为 80 时它正在工作,但在我的情况下我需要使用另一个端口 81(因为 80 已用于另一个应用程序)。我可以从 80 端口重定向到 81 端口吗?
  • 那么你的意思是你需要一个 URL Rewrite rule for http://example.com:80 to http://example.com:81 or for http://example.com:80 to https://example.com:81?请澄清一下,这可能有助于我们了解您的要求。
  • @Deepak-MSFT 我想要从 http://example.com:80 重定向到 https://example.com:443 因为现在当我想打开 example.com 时我得到这个错误“Requested URL example.com:80 “。有关信息,我将端口 81 用于 http,将端口 443 用于 https。

标签: iis https url-rewriting url-rewrite-module


【解决方案1】:

对于 http://example.com:80https://example.com:443,您在问题中发布的规则是正确的,并且在我这边工作正常。

如果它在您这边不起作用,您可以检查失败的请求跟踪日志,它可能会为您提供有关该问题的信息。问题可能是别的。

对于http://example.com:81https://example.com:443,您可以参考以下规则。

<rule name="Redirect with port" stopProcessing="true">
     <match url=".*" />
     <conditions>
            <add input="{HTTP_HOST}" pattern="^(.*):81$" />
     </conditions>
            <action type="Redirect" url="https://{C:1}:443/{R:0}" />
</rule>

输出:

如果您还有其他问题,请告诉我。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-05-23
    • 1970-01-01
    • 1970-01-01
    • 2015-11-02
    • 1970-01-01
    • 2013-06-02
    • 2020-04-16
    相关资源
    最近更新 更多