【问题标题】:Rewrite root url call to subfolder将根 url 调用重写到子文件夹
【发布时间】:2017-07-25 10:30:25
【问题描述】:

我的单页应用 index.html 位于子文件夹中。我希望人们在访问根 URL 时看到它。此重写规则中缺少什么?

<rewrite>
  <rules>
    <rule name="SPA rewrite">
      <match url="http://app.local" />
      <action type="Rewrite" url="http://app.local/SPA/dist" />
    </rule>
  </rules>
</rewrite>

【问题讨论】:

  • 您在同一个应用程序中是否还有其他内容或资源。您能补充一下还有哪些其他内容吗?例如,您是否有一些动态内容 api/product/something 等也从应用程序提供,或者它只是静态网站?因为根据条件我们可以在不影响网站中任何其他内容(动态和静态)的情况下制定规则。

标签: asp.net iis url-rewriting


【解决方案1】:

你的规则应该是这样的:

<rule name="SPA rewrite" stopProcessing="true">
  <match url=".*" />
  <conditions logicalGrouping="MatchAll">
      <add input="{HTTP_HOST}" pattern="app.local" />
      <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
      <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
  </conditions>
  <action type="Rewrite" url="/SPA/dist" />
</rule>

在您的回答中,您在&lt;match url= 部分使用了不正确的模式。而对于 SPA,您不需要重写文件和目录

【讨论】:

    猜你喜欢
    • 2023-04-07
    • 1970-01-01
    • 2023-03-26
    • 2020-01-08
    • 2013-10-16
    • 2013-11-08
    • 2021-11-20
    • 1970-01-01
    • 2019-08-14
    相关资源
    最近更新 更多