[英]IIS Rewrite 2 Angular applications
I have 2 Angular applications. 我有2个Angular应用程序。 One in my main domain and the other one in a virtual directory called "merchant", inside this domain.
一个在我的主域中,另一个在这个域内的虚拟目录“ merchant”中。 I want to have rewrite rules for both so that I can enter the URL in the address bar without having 404 page.
我希望两者都具有重写规则,以便我可以在地址栏中输入URL而无需404页面。 For this I put a web.config in both folders, but I am not able to get both applications rewrite rules working at the same time.
为此,我将web.config放在两个文件夹中,但无法使两个应用程序重写规则同时起作用。
In the main application web.config I have 在主应用程序web.config中,我有
<rewrite>
<rules>
<rule name="block" stopProcessing="true">
<match url="^merchant/(.*)$" />
<action type="Redirect" url="merchant/{R:1}" />
</rule>
<rule name="Application Routes" patternSyntax="Wildcard">
<match url="*" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
With this conf, the rewriting works well for the main application, but not for the second. 有了这个conf,重写对于主应用程序很好,但是对第二个应用程序则不好。 I thought the first rule would redirect to the virtual folder web.config but seems it's not.
我以为第一个规则将重定向到虚拟文件夹web.config,但事实并非如此。 Below the rules in my virtual folder web.config:
在我的虚拟文件夹web.config中的规则下方:
<rewrite>
<rules>
<rule name="AngularJS 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="/merchant/" />
</rule>
</rules>
</rewrite>
Of course if I remove all the rules from the main web.config, the second is working, but not the first anymore... 当然,如果我从主web.config中删除所有规则,则第二个规则正在运行,但第一个不再可用...
How can I get both at the same time? 如何同时获得两者?
Finally I found a solution. 终于我找到了解决方案。 As commented by funkizer I had to put all rules in the same web.config Below the main web.config with 2 rules
正如funkizer所说,我必须将所有规则放在相同的web.config中,并在主web.config下方添加2条规则
<rewrite>
<rules>
<rule name="AngularJS Routes" stopProcessing="true">
<match url="^merchant/(.*)$" />
<conditions >
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="merchant/" />
</rule>
<rule name="Application Routes" patternSyntax="Wildcard">
<match url="*" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
I also had to keep the other web.config but I removed all rules inside. 我还必须保留另一个web.config,但删除了其中的所有规则。 Now both applications can be accessed with direct url
现在可以使用直接网址访问这两个应用程序
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.