当查询参数存在但没有根文件时 IIS URL 重写规则

问题描述 投票:0回答:1

我有一个由 IIS 提供给

example.com/mywebapp
的 Web 应用程序。默认文件是
index.html
,因此当有人加载
example.com/mywebapp
时 - index.html 就是实际加载的内容(非常标准的行为)。如果有人使用查询参数请求 Web 应用程序,但没有文件名(即
example.com/mywebapp/?params=123
),则 URL 似乎会自动“更正”为
example.com/mywebapp?params=123
- IIS 将其解释为文件,
mywebapp
在根级别网络服务器
example.com
...而这个不存在。

是否可以使用

mywebapp
目录中的 web.config 文件并利用重写或重定向规则,使
example.com/mywebapp/?params=123
变为
example.com/mywebapp/index.html?params=123
--- 但仅当存在 URL 参数时?

regex redirect iis url-rewriting web-config
1个回答
0
投票

请尝试以下规则:

<system.webServer>
  <rewrite>
    <rules>
      <rule name="Rewrite Params to Index" stopProcessing="true">
        <match url=".*" />
        <conditions>
          <add input="{QUERY_STRING}" pattern=".+" />
        </conditions>
        <action type="Rewrite" url="index.html" appendQueryString="true" />
      </rule>
    </rules>
  </rewrite>
</system.webServer>

这是我的测试结果:

© www.soinside.com 2019 - 2024. All rights reserved.