URL 重写原因 "This page can’t be displayed"

URL Rewrite causes "This page can’t be displayed"

我已经在服务器级别实现了 URL 重写,因为我想将所有符合特定规则的 HTTP 和 HTTPS 请求重定向到我的实际站点,并且只有在用户访问我的网站时才会进行重定向实际站点。这些规则最初运行良好。但是,在我的实际站点上反复触发 CTRL+R 似乎使我的站点无法访问。然后将错误 [​​=55=] 返回给用户。此测试是在 Windows x64 上的 IE 11 浏览器上完成的,我的 Web 服务器是 Windows Server 2012 R2 上的 IIS 8.5。重定向返回的HTTP响应码配置为307。

当我在我的 IIS 服务器上打开失败请求路由时,我在失败请求日志中看到关于 REWRITE_DISABLED_KERNEL_CACHE 的警告消息。这是页面 returns "This page can't be displayed".

的时候

禁用我的 URL 重写规则会立即使我的 HTTP 和 HTTPS 站点再次可访问,并且我已验证重定向不再有效。此后启用相同的规则但仅在我的 HTTPS 站点上有效。

如下是我的重定向规则

<system.webServer>
    ...
    <rewrite>
        <globalRules>
            <clear />
            <rule name="HTTPS to HTTP" enabled="true" stopProcessing="true">
                <match url="^(downloads?/?)?$" />
                <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                    <add input="{REQUEST_URI}" pattern="http://.*?/downloads/" negate="true" />
                </conditions>
                <action type="Redirect" url="http://{HTTP_HOST}/downloads/" appendQueryString="false" redirectType="Temporary" />
            </rule>
        </globalRules>
        <outboundRules>
        </outboundRules>
    </rewrite>
    ...
</system.webServer>

基本上,如果请求命中以下任何示例 URL,我将重定向它们:

1) http://fqdn/download

2) http://fqdn/download/

3) https://fqdn/downloads

4) https://fqdn/downloads/

5) https://fqdn/download

6) https://fqdn/download/

如果请求直接到达我的站点,我不会重定向:

当我访问我的实际站点时,我意识到重定向规则仍在应用。所以我怀疑这里可能有 2 个不同的问题。

1) 将请求发送到 http://fqdn/downloads/

时应用无限重定向规则

2) REWRITE_DISABLED_KERNEL_CACHE

的一些未知问题

由于您对 REQUEST_URI 的错误假设以及缺少 HTTPS 检查,您遇到了无限重定向的麻烦。

{REQUEST_URI} 包含 URL 的 路径 ,包括带有 [=24= 的 查询字符串 ]前导斜杠(从未有过详细记录),从不包含 uri 方案或主机名。所以,你有误报。

http(s)://<host>:<port>/<path>?<querystring>

这是一条不言自明的规则。

<rule name="Force Http downloads page" stopProcessing="true">

    <!-- If the url starts with download or downloads with an optional trailing slash -->
    <match url="^downloads?/?$" />

    <!-- Redirect -->
    <action type="Redirect" url="http://{HTTP_HOST}/downloads/" appendQueryString="false" redirectType="Temporary" />

    <!-- When -->
    <conditions logicalGrouping="MatchAny">
        <!-- REQUEST_URI does not start with "/downloads/" -->
        <add input="{REQUEST_URI}" pattern="^/downloads/" negate="true" />

        <!-- Or -->

        <!-- HTTPS is not off -->
        <add input="{HTTPS}" pattern="^off$" negate="true" />
    </conditions>
</rule>

希望对您有所帮助。