IIS 8.5重写规则子目录和ReactJs

时间:2019-06-20 23:37:19

标签: reactjs iis url-rewriting

我一直在努力了解IIS 8.5中的重写规则,并希望获得一些帮助。基本上,对于React应用程序,我需要重写所有网址以在index.html以及可选的queryparams处输入。

React应用只能在Web服务器的子目录中使用,因为它只是主站点的扩展

所以对于资产(文件夹),静态(文件夹)和manifest.json(文件),我不需要它来重写url。这些将属于

  • www.some-site.com/catalog/door-selector/(文件夹或文件以及index.html)

所有路线也将从此处开始,请参见2个示例:

  • www.some-site.com/catalog/door-selector/doors
  • www.some-site.com/catalog/door-selector/doors/(门的名称)

所以我想出了以下内容:(不起作用)

<rule name="Door Selector Door" patternSyntax="ExactMatch">
  <match  url="^catalog/door-selector/.+" />
  <conditions logicalGrouping="MatchAll">
    <add input="{REQUEST_URI}" pattern="^~/static/~(.*)" negate="true" />
    <add input="{REQUEST_URI}" pattern="^~/assets/~(.*)" negate="true" />
    <add input="{REQUEST_URI}" pattern="^~/manifest.json" negate="true" /> 
  </conditions>
  <action type="Rewrite" url="catalog/door-selector/index.html" appendQueryString="true"/>
</rule>

通过简单的重写,没有任何条件,我可以使它正常工作,但我希望仅使用几个规则即可。

注意:我忘记了某些资产来自生产服务器。那就是重写URL的一部分!

最终规则确定于:

<rule name="Door Selector React" enabled="true">
  <match  url="catalog/door-selector/(.*)" />
  <conditions logicalGrouping="MatchAll">
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
  </conditions>
  <action type="Rewrite" url="catalog/door-selector/index.html" appendQueryString="true"/>
</rule>

1 个答案:

答案 0 :(得分:1)

您可以使用以下url重写规则:

 <rule name="React Rewrite" enabled="true" patternSyntax="ECMAScript">
                <match url="(.*)" negate="false" />
                <action type="Rewrite" url="/index.html" />
                <conditions logicalGrouping="MatchAll">
                    <add input="{REQUEST_URI}" pattern="^(/assets/)" negate="true" />
                    <add input="{REQUEST_URI}" pattern="^(/static/)" negate="true" />
                    <add input="{REQUEST_URI}" pattern="manifest.json" negate="true" />
                </conditions>
            </rule>

注意:如果要匹配应用程序或站点的子目录,可以根据需要设置条件。 或者,您可以共享您的站点文件夹结构,以便我们为您提供更多帮助。

关于, 贾帕(Jalpa)

相关问题