React MVC App的IIS重写条件 [英] IIS rewrite condition for React MVC App

查看:75
本文介绍了React MVC App的IIS重写条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个create-react-app,并试图发布到生产站点.

I have created a create-react-app and am trying to publish to a production site.

我的目标是使对/api/*的所有调用都传递到MVC Server应用程序的控制器.还提供/content/*和/static/*

My goal is to have all calls to /api/* go through to the MVC Server application's controller. Also serve any static files from /content/* and /static/*

所有其他调用应提供1个文件/index.html(这是我的react文件所在的位置,它们将处理路由.

All other calls should serve the 1 file /index.html (which is where my react files live and they will handle the routing.

我正在使用IIS Rewrite模块,并且试图将请求的URL不匹配模式"与regexp一起使用.

I am using the IIS Rewrite module, and I am trying to use the requested URL "Does Not MAtch the pattern" with regexp.

我当前的IIS安装程序将忽略如果模式匹配则不要重写",并将所有内容重写为index.html

MY current IIS setup ignores the "do not rewrite if pattern matches" and rewrites everything to index.html

这是IIS设置:

,这是web.config.我不确定自己在做什么错.

and here is the web.config. I'm not sure what I am doing wrong.

 <rewrite>
            <rules>
                <rule name="React Rewrite" enabled="true" patternSyntax="ECMAScript">
                    <match url="(.*)/api/(.*)|(.*)/content/(.*)|(.*)/static/(.*)" negate="true" />
                    <action type="Rewrite" url="/index.html" />
                    <conditions>
                    </conditions>
                </rule>
            </rules>
        </rewrite>

推荐答案

我已经通过使用条件解决了它.我的解决方案是:

I've solved it by using the Conditions. My solution is:

<rewrite>
            <rules>
                <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="^(/api/)" negate="true" />
                        <add input="{REQUEST_URI}" pattern="^(/content/)" negate="true" />
                        <add input="{REQUEST_URI}" pattern="^(/static/)" negate="true" />
                    </conditions>
                </rule>
            </rules>
        </rewrite>

这篇关于React MVC App的IIS重写条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆