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

时间:2019-04-28 05:20:59

标签: url-rewriting iis-7.5 url-redirection web.config-transform

我正在使用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" />时(删除?id = 63),它为什么起作用,为什么?我该怎么办?

1 个答案:

答案 0 :(得分:1)

据我所知,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>