angular - IIS URL 重写一些覆盖其他规则的规则
问题描述
我们正在将我们的主站点分解为微服务。最初,当我们拆分站点的一部分时,它将在我们的原始服务器上成为它自己的站点,直到它可以移动到它自己的容器中。
该站点当前是一个 Angular 站点,因此您会看到我们有规则将所有内容都重写到 index.html。我正在尝试添加一个额外的规则,所以如果它找到了 url。www.domainname.com/api/auth/.*
至localhost:8001/{R:1}
我的理解是它将从 /auth/ 之后的 url 中获取所有内容并将其更改为 localhost:8001/{stuff after}
发生的事情是它遵循将所有内容指向索引文件的规则,并且似乎忽略了我的新规则。我第一次也是最后一次尝试过,所以我假设我的规则一定有问题。
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Api Rule">
<match url="domainname.com/api/auth/.*" />
<action type="Rewrite" url="localhost:8001/{R:1}" appendQueryString="false" />
</rule>
<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="/" />
</rule>
<rule name="CanonicalHostNameRule1">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.domainname\.com$" negate="true" />
</conditions>
<action type="Redirect" url="http://www.domainname.com/{R:1}" />
</rule>
<rule name="Redirect to https" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
解决方案
规则的评估顺序与它们指定的顺序相同。(来自文档:URL 重写模块配置参考 - 规则评估)
元素的url
属性match
与 URL 的 PATH 部分一起使用。您不应指定域。
<rule name="Api Rule">
<match url="^api/auth/(.*)" />
<action type="Rewrite" url="localhost:8001/{R:1}" appendQueryString="false" />
</rule>
如果要与域匹配,可以添加条件
<rule name="Api Rule">
<match url="^api/auth/(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^domain\.com$" />
</conditions>
<action type="Rewrite" url="localhost:8001/{R:1}" appendQueryString="false" />
</rule>
推荐阅读
- java - 对于每个循环添加所有人口
- python - 从字典中提取数据
- java - 调用嵌套recyclerview适配器获取数据
- node.js - 如何在 index.js 文件中为 firebase-auth 提供服务密钥文件的路径?
- javascript - 如何在angularjs中创建一个简单的if then else?
- android - IllegalStateException:当我第二次尝试显示 AlertDialog 时
- go - 解析具有深层结构和数组值的 yaml
- asp.net-core - Azure SignalR 服务 - 多服务器配置
- lit-element - LitElement - 如果在 LitElement 渲染方法中的表达式,如何使用 javascript 创建 dom-if 重新标记行为?
- c++ - 访问“父”或“所有者”函数 C++