首页 > 解决方案 > iis7.5,web.config 如何将不存在的文件(页面)重定向到另一个页面?

问题描述

我正在使用iis-7.5和 web.config 文件。

我想重定向"somepage.asp?id=63""somepage/10.html".

我的 web.config 是这样的:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="301 Redirect 2" stopProcessing="true">
                    <match url="somepage.asp?id=63" />
                    <action type="Redirect" url="somepage/10.html" redirectType="Permanent" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

它不起作用,当我更改<match url="somepage.asp?id=63" /><match url="somepage.asp" />, (delete ?id=63) 时,它起作用了,为什么?我能怎么做?

标签: url-rewritingiis-7.5url-redirectionweb.config-transform

解决方案


据我所知,url 重写匹配 url 模式与查询字符串不匹配。

如果你想根据查询字符串重定向url,我建议你可以尝试使用条件。

更多细节,你可以参考下面的 url 重写规则:

            <rule name="Redirect according to query string" stopProcessing="true">
                <match url="somepage.asp" />
                <conditions>
                    <add input="{QUERY_STRING}" pattern="id=63" />
                </conditions>
                <action type="Redirect" url="somepage/10.html" appendQueryString="false" />
            </rule>

推荐阅读