【发布时间】:2021-02-04 21:26:30
【问题描述】:
我有一个 IIS 网站 http://localhost:4200,在该网站下有两个文件:url.asp 和 url.html。
文件如下所示:
url.asp:
<h2>Query Strings: <%= Request.QueryString %></h2>
url.html:
<html lang="en">
<body>
<h2 id="location" />
<script type="text/javascript">
document.getElementById('location').innerText = `Query Strings: ${location.search}`;
</script>
</body>
</html>
基本上这两个文件都会在 URL 中打印查询字符串。
我还有一个 IIS 虚拟目录 http://localhost/abc,其中有一个 web.config 文件,其中仅包含 URL 重写规则,如下所示:
web.config:
<?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>
问题
当我点击http://localhost/abc/z123 时,我得到:
查询字符串:p=123
这是我所期待的。此请求被重定向(重写)到url.asp 文件。
但是,当我点击 http://localhost/abc/123 时,我得到:
查询字符串:
在这种情况下不打印查询字符串。此请求被重定向(重写)到url.html 文件。
因此,通过 IIS URL 重写,如果我将查询字符串传递给 asp 文件,它会获取查询字符串。但是当我将查询字符串传递给 HTML 文件时,它没有得到它。
谁能解释一下为什么会这样?
【问题讨论】:
-
您好,问题解决了吗?如果您认为我的回复对您有帮助,您可以将其标记为答案。
标签: html windows iis url-rewrite-module