如何匹配除一个之外的所有组合?
How to match on all combinations except one?
我有一组 ARR redirect/rewrite 规则可以执行此操作:
- 每当子域
tfs
在 URL 中时重定向到 HTTPS
- 从网络上的不同服务器拉取内容。
这是我的配置:
<rule name="TFS Redirect" enabled="true" stopProcessing="true">
<match url="^((?!tfs).)*$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="tfs.domain.com" />
</conditions>
<action type="Redirect" url="https://tfs.domain.com/tfs" appendQueryString="false" />
</rule>
<rule name="TFS Rewrite" enabled="true" stopProcessing="true">
<match url="^tfs(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="http://server3:8080/{R:0}" />
</rule>
问题在于此设置与我的 Let's Encrypt 配置冲突。我需要以某种方式对除此 URL:
之外的所有内容执行上述规则
http://tfs.domain.com/.well-known/acme-challenge/*
这是对驱动自动证书更新过程的传入远程质询的回答。但是,由于规则的原因,ACME 服务器无法访问本地 IIS 进行验证,并且证书不会被续订。
我怎样才能允许这个 URL 通过,同时捕获其他所有内容?有没有办法为条件添加例外?或者我应该完全删除该条件并完全依赖 RegEx 表达式吗?
经过几个小时的 RegEx fiddling,我想出了解决办法。
这是新规则:
<rule name="TFS Redirect" enabled="true" stopProcessing="true">
<match url="^(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="^OFF$" />
<add input="{HTTP_HOST}" pattern="^tfs\.domain\.com$" />
<add input="{URL}" pattern="^/\.well-known*" negate="true" />
</conditions>
<action type="Redirect" url="https://tfs.domain.com/tfs" appendQueryString="false" redirectType="Found" />
</rule>
我不想承认我不知道我从哪里得到的那个早先的表达,但它是 WAY off。我所要做的就是退缩,稍微调整一下条件,一切都会顺利进行。
此规则捕获并重定向这些请求:
- 对
tfs.domain.com
的所有请求的非 HTTPS URL
- 以上所有,除了那些在
{URL}
服务器变量 中不以/.well-known
开头的
仅供参考,我在找到 this 后选择了 302 重定向。
我有一组 ARR redirect/rewrite 规则可以执行此操作:
- 每当子域
tfs
在 URL 中时重定向到 HTTPS
- 从网络上的不同服务器拉取内容。
这是我的配置:
<rule name="TFS Redirect" enabled="true" stopProcessing="true">
<match url="^((?!tfs).)*$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="tfs.domain.com" />
</conditions>
<action type="Redirect" url="https://tfs.domain.com/tfs" appendQueryString="false" />
</rule>
<rule name="TFS Rewrite" enabled="true" stopProcessing="true">
<match url="^tfs(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="http://server3:8080/{R:0}" />
</rule>
问题在于此设置与我的 Let's Encrypt 配置冲突。我需要以某种方式对除此 URL:
之外的所有内容执行上述规则http://tfs.domain.com/.well-known/acme-challenge/*
这是对驱动自动证书更新过程的传入远程质询的回答。但是,由于规则的原因,ACME 服务器无法访问本地 IIS 进行验证,并且证书不会被续订。
我怎样才能允许这个 URL 通过,同时捕获其他所有内容?有没有办法为条件添加例外?或者我应该完全删除该条件并完全依赖 RegEx 表达式吗?
经过几个小时的 RegEx fiddling,我想出了解决办法。
这是新规则:
<rule name="TFS Redirect" enabled="true" stopProcessing="true">
<match url="^(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="^OFF$" />
<add input="{HTTP_HOST}" pattern="^tfs\.domain\.com$" />
<add input="{URL}" pattern="^/\.well-known*" negate="true" />
</conditions>
<action type="Redirect" url="https://tfs.domain.com/tfs" appendQueryString="false" redirectType="Found" />
</rule>
我不想承认我不知道我从哪里得到的那个早先的表达,但它是 WAY off。我所要做的就是退缩,稍微调整一下条件,一切都会顺利进行。
此规则捕获并重定向这些请求:
- 对
tfs.domain.com
的所有请求的非 HTTPS URL
- 以上所有,除了那些在
{URL}
服务器变量 中不以
/.well-known
开头的
仅供参考,我在找到 this 后选择了 302 重定向。