【问题标题】:IIS Rewrite Module and sub applications / React-RouterIIS 重写模块和子应用程序 / React-Router
【发布时间】:2019-10-03 00:29:32
【问题描述】:

好的,这与其他问题类似,但我不熟悉 url rewrite。

我在 IIS 下托管(希望仅用于开发和测试)一个 React 应用程序。

如果托管在站点文件夹的根目录中,则一切正常

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Static Assets" stopProcessing="true">
          <match url="([\S]+[.](svg|js|css|png|gif|jpg|jpeg))" />
          <action type="Rewrite" url="{R:1}" />
        </rule>
        <rule name="ReactRouter Routes" stopProcessing="true">
          <match url=".*" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          </conditions>
          <action type="Rewrite" url="/index.html" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

但我需要它在子应用程序中工作。例如:http://myserver:8888/myapp。其中 myapp 是子应用程序。

IIS 图:

网站 - 我的网站 - 我的应用程序

包含路由的 url 的更好示例:http://myserver:8888/myapp/1234/abcd。 1234 和 abcd 是路由值/参数。

contents of my app directory are:
   index.html
   main.a9e1df0325f4fdb57e7e.js
   vendors~main.c8848853e10f698af19d.js
   web.config

谢谢

吉娜

【问题讨论】:

    标签: iis url-rewriting react-router


    【解决方案1】:

    您可以在 iis 的任何子应用程序中托管您的应用程序,但请注意定义正确的内容提供路径。似乎您想托管静态内容,因此您不能在 url 中使用路由参数,因此这些参数由 asp.net 使用。静态内容由 iis 提供。您可以尝试使用此网址在 myapp 中提供内容:

    http://myserver:8888/myapp/index.html
    

    【讨论】:

    • 我知道如何在 IIS 中将普通应用程序作为子应用程序托管。我的困难是反应应用程序。
    猜你喜欢
    • 2013-06-02
    • 1970-01-01
    • 2013-05-09
    • 1970-01-01
    • 2017-10-10
    • 2014-05-06
    • 2018-08-02
    • 2011-12-04
    • 2012-06-01
    相关资源
    最近更新 更多