Html IIS URL重写未附加查询字符串

Html IIS URL重写未附加查询字符串,html,windows,iis,url-rewrite-module,Html,Windows,Iis,Url Rewrite Module,我有一个IIS网站http://localhost:4200下面有两个文件:url.asp和url.html 这些文件看起来是这样的: url.asp: <h2>Query Strings: <%= Request.QueryString %></h2> 问题 当我点击http://localhost/abc/z123我得到: 查询字符串:p=123 这就是我所期待的。此请求被重定向(重写)到url.asp文件 但是,当我点击http://localhost

我有一个IIS网站
http://localhost:4200
下面有两个文件:
url.asp
url.html

这些文件看起来是这样的:

url.asp:

<h2>Query Strings: <%= Request.QueryString %></h2>
问题

当我点击
http://localhost/abc/z123
我得到:

查询字符串:p=123

这就是我所期待的。此请求被重定向(重写)到
url.asp
文件

但是,当我点击
http://localhost/abc/123
我得到:

查询字符串:

在这种情况下不打印查询字符串。此请求被重定向(重写)到
url.html
文件

因此,通过IIS URL重写,如果我将查询字符串传递给asp文件,它将获得查询字符串。但是,当我将查询字符串传递给HTML文件时,它不会得到它


有人能解释一下为什么会这样吗?

这是因为在InboundRule2中,您的{R:1}是http://localhost/abc/123:

您需要按如下方式修改重写规则:

此时的查询字符串应为{R:2}:

           <rule name="InboundRule2">
                <match url="(abc)/(.*)" />
                <action type="Rewrite" url="http://localhost:4200/url.html?p={R:2}" />
            </rule>


您可以使用重定向来解决此问题。

很抱歉,我认为我无法理解我的问题。具有URL重写规则的web.config位于名为
abc
http://localhost/abc
),不在
http://localhost
。URL重写适用于规则“InboundRule1”和“InboundRule2”,一个重定向到“.asp”文件,另一个重定向到“.html”文件。问题是,.asp文件接收我通过URL重写规则传递的查询字符串,.html文件不接收。我不知道如何解释这一点,也不知道如何寻找解释。当您删除InboundRule1时,是否仍存在此问题?是的。我愿意。“InboundRule1”只是为了演示在某些情况下传递查询字符串。我的问题实际上是关于“内在规则2”。嗨,问题解决了吗?如果你认为我的回答对你有帮助,你可以把它标记为回答。
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="InboundRule1" stopProcessing="true">
                    <match url="z(.*)" />
                    <action type="Rewrite" 
                            url="http://localhost:4200/url.asp?p={R:1}"
                            appendQueryString="true"
                            logRewrittenUrl="true" />
                </rule>
                <rule name="InboundRule2" stopProcessing="true">
                    <match url="(.*)" />
                    <action type="Rewrite" 
                            url="http://localhost:4200/url.html?p={R:1}"
                            appendQueryString="true"
                            logRewrittenUrl="true" />
                </rule>
            </rules>
        </rewrite>
        <httpRedirect enabled="false" />
    </system.webServer>
</configuration>
           <rule name="InboundRule2">
                <match url="(abc)/(.*)" />
                <action type="Rewrite" url="http://localhost:4200/url.html?p={R:2}" />
            </rule>