gpt4 book ai didi

IIS URL 重写规则

转载 作者:行者123 更新时间:2023-12-04 14:58:13 24 4
gpt4 key购买 nike

我有一个 AngularJS 应用程序,它利用 URL 重写进行链接。我的重写规则如下:

<rewrite>
<rules>
<rule name="MainRule" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="Pattern" pattern="^api/(.*)" negate="false" />
</conditions>
<action type="Rewrite" url="Default.cshtml" />
</rule>
</rules>

我在 SO 上找到了这个解决方案: How do I configure IIS for URL Rewriting an AngularJS application in HTML5 mode?并进行了一项修改以允许我的 API 通过。

本质上,我想将所有请求重定向到 Default.cshtml除了对我的 Web API 的调用。当我在基本 URL 上加载应用程序时,这非常有效,例如: localhost/myapp .但是,如果我在角度路线上重新加载页面,例如: localhost/myapp/dashboard它没有说:
<Error><Message>No HTTP resource was found that matches the request URI 'http://localhost/myapp/dashboard'.</Message>
<MessageDetail>No type was found that matches the controller named 'dashboard'.</MessageDetail></Error>

我有一个解决方法:
 <rewrite>
<rules>
<rule name="Default" stopProcessing="true">
<match url="^(?!lib|api|dist|assets|app/|bower|common|main|signalr|templates|bower_components/).*" />
<action type="Rewrite" url="Default.cshtml" />
</rule>
</rules>
</rewrite>

它工作正常。我有什么想法可以利用上面更干净的解决方案并仍然完成重写?

最佳答案

我需要改变模式和改变{REQUEST_FILE}{REQUEST_URI}在几个地方。在这里查看我的演示:

<rewrite>
<rules>
<rule name="MainRule" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" matchType="Pattern" pattern="api/(.*)" negate="true" />
<add input="{REQUEST_URI}" matchType="Pattern" pattern="signalr/(.*)" negate="true" />
</conditions>
<action type="Rewrite" url="Default.cshtml" />
</rule>
</rules>
</rewrite>

关于IIS URL 重写规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25644287/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com