无法获得静态重定向以使用 IIS Url Rewrite 2.0 [英] Can't get static redirects to work with IIS Url Rewrite 2.0

查看:85
本文介绍了无法获得静态重定向以使用 IIS Url Rewrite 2.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在本地运行以下 IIS URL 重写设置,但无法使其工作(来自 web.config):

 <rewriteMaps><rewriteMap name="StaticRedirects"><add key="^tvb/" value="/tv/"/></rewriteMap></rewriteMaps><规则><规则名称="StaticRedirectsRule" stopProcessing="true"><match url=".*"/><条件><add input="{StaticRedirects: {REQUEST_URI}}" matchType="Pattern" pattern="(.+)" ignoreCase="true" negate="false"/></条件><action type="Redirect" url="{C:1}" appendQueryString="true"/></规则></规则></rewrite>

尝试打开 url http://localhost/tvb/http://localhost/tvb/?a=b 返回 404 错误而不是将我重定向到 http://localhost/tv(带或不带查询字符串).

我在 stackoverflow 上发现了类似的帖子,我已经尝试了他们推荐的内容:回收应用程序池、重新启动 IIS 服务、用 URL 和/或 REQUEST_FILENAME 替换 REQUEST_URI,但这些更改都没有产生影响.

谁能看到我哪里出错了?

解决方案

我遇到了同样的问题,用 PATH_INFO 替换 REQUEST_URI 解决了这些问题.

这是链接 https://forums.iis.net/post/1883056.aspx

推理:'这是因为 REQUEST_URI 包含包含查询字符串的整个请求 URL.由于重写映射中的键不包含查询字符串,因此映射查找失败.'

Running the following IIS URL Rewrite setup locally and can't get it to work (from web.config):

        <rewrite>
        <rewriteMaps>
            <rewriteMap name="StaticRedirects">
                <add key="^tvb/" value="/tv/" />
            </rewriteMap>
        </rewriteMaps>
        <rules>
            <rule name="StaticRedirectsRule" stopProcessing="true">
                <match url=".*" />
                <conditions>
                    <add input="{StaticRedirects: {REQUEST_URI}}" matchType="Pattern" pattern="(.+)" ignoreCase="true" negate="false" />
                </conditions>
                <action type="Redirect" url="{C:1}" appendQueryString="true" />
            </rule>
        </rules>
    </rewrite>

Trying to open the url http://localhost/tvb/ or http://localhost/tvb/?a=b returns a 404 error instead of redirecting me to http://localhost/tv (with or without query string).

I've found similar posts here on stackoverflow and I've tried what they recommended: recycling the app pool, restarting the IIS service, replacing REQUEST_URI with URL and/or REQUEST_FILENAME but none of these changes made a difference.

Can anyone see where I went wrong?

解决方案

I had the same problem, and replacing REQUEST_URI with PATH_INFO fixed the issues.

Here is the link https://forums.iis.net/post/1883056.aspx

Reasoning: 'This is because REQUEST_URI contains the entire requested URL that includes the query string. Since the keys in the rewrite map do not contain the query string the map lookup fails.'

这篇关于无法获得静态重定向以使用 IIS Url Rewrite 2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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