URL重写导致“此页面无法显示” [英] URL Rewrite causes "This page can’t be displayed"

查看:251
本文介绍了URL重写导致“此页面无法显示”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have implemented URL Rewriting at the server level as I wanted to redirect all HTTP and HTTPS requests that matches a certain rule to my actual site, and redirection should only take place if the users are hitting my actual site. The rules works fine initially. However, triggering CTRL+R repeatedly on my actual site seems to render my site unaccessible. The error "This page can't be displayed" is then returned to the user. This test was done on IE 11 browser on Windows x64, and my web server is IIS 8.5 on Windows Server 2012 R2. The HTTP response code returned for redirect is configured as 307.

当我在IIS服务器上打开失败请求路由时,我在失败请求中的REWRITE_DISABLED_KERNEL_CACHE上看到一条警告消息日志。这是页面返回此页面无法显示的时间。

When I turn on Failed Request Routing on my IIS server, I see a warning message on REWRITE_DISABLED_KERNEL_CACHE in the Failed Request Logs. This was the time when the page returns "This page can't be displayed".

禁用我的URL重写规则会立即再次访问我的HTTP和HTTPS站点,我已经确认重定向不再有效。之后在我的HTTPS站点上启用相同的规则只会起作用。

Disabling my URL Rewrite rule would immediately render both my HTTP and HTTPS sites accessible once again, and I've verified that redirect no longer works. Enabling the same rule thereafter but on my HTTPS site only would work.

以下是我的重定向规则

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

基本上,如果请求到达以下任何示例网址,我会重定向它们:

Basically, if the request hits any of the following example URLs, I will redirect them:

1) http:// fqdn / download

2) http:// fqdn / download /

3) https:// fqdn / downloads

4) https:// fqdn / downloads /

5) https:// fqdn / download

6) https:// fqdn / download /

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

I will not redirect, if the request hits my site directly:

  • http://fqdn/downloads/

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

When I hit my actual site, I realise that the redirection rule is still being applied. So I suspect there could be 2 different issues over here.

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

1) An infinite redirection rule being applied when requests are sent to http://fqdn/downloads/

2)REWRITE_DISABLED_KERNEL_CACHE

2) Some unknown problem with REWRITE_DISABLED_KERNEL_CACHE

推荐答案

由于您对 REQUEST_URI的错误假设,您遇到了无限重定向的问题且缺少 HTTPS 检查。

{REQUEST_URI} 包含网址的路径,包括查询字符串,带有前导斜杠(从未进行过文档记录),从不包含uri方案或主机名。所以,你有误报。

{REQUEST_URI} contains URL's path, including the query string with a leading slash (never been welldocumented), never contains uri scheme or hostname. So, you have a false positive.


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

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

Here's a self-explanatory rule.

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

希望有所帮助。

这篇关于URL重写导致“此页面无法显示”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆