regex - IIS Rewrite ARR sub folders and main site on root URL
问题描述
I might just be missing something small.
I have several sites that I have set up with ARR and they work except for the base URL which should still continue to point to the legacy app.
It should resolve to the following:
- www.mysite.com/app1 --> App1
- www.mysite.com/app2 --> App2
- www.mysite.com/ --> Legacy App (Not working)
I understand that the rewrite rules are check in the order that it is placed, therefore I placed the legacy app last. I figure my matching URL regex is suspect.
Is this even possible? Would appreciate the help so much.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Reverse Proxy to App1" stopProcessing="true">
<match url="^app1/(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="http://pc1.local/{R:1}" />
</rule>
<rule name="Reverse Proxy to App2" stopProcessing="true">
<match url="^app2/(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="http://pc2.local/{R:1}" />
</rule>
<rule name="Redirect HTTP to HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
<rule name="Reverse Proxy to Legacy App" 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="http://legacypc.local/{R:1}" />
</rule>
</rules>
<outboundRules>
<rule name="Add STS headers to HTTPS response">
<match serverVariable="RESPONSE_Strict_Transport_Security" pattern=".*"/>
<conditions>
<add input="{HTTPS}" pattern="on"/>
</conditions>
<action type="Rewrite" value="max-age=31536000"/>
</rule>
<rule name="Ensure secure Cookies" preCondition="Missing secure cookie">
<match serverVariable="RESPONSE_Set_Cookie" pattern=".*" negate="false" />
<action type="Rewrite" value="{R:0}; secure" />
</rule>
<preConditions>
<preCondition name="Missing secure cookie">
Don't remove the first line here, it does do stuff!
<add input="{RESPONSE_Set_Cookie}" pattern="." />
<add input="{RESPONSE_Set_Cookie}" pattern="; secure" negate="true" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
<defaultDocument enabled="false" />
</system.webServer>
</configuration>
解决方案
似乎当您请求 url 时www.mysite.com/
,它被视为目录,因此它与条件不匹配<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
。
如果您的应用程序运行时没有任何目录,我认为您可以直接删除<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
“反向代理到旧版应用程序”规则中的第二个条件。然后它可以实现您的要求。
推荐阅读
- r - 第三个变量的ggplot黄土线色标
- sql-server - 用分隔符连接重复项
- gradle - 如何在 Gradle 4.10.3 中使用 Kotlin Gradle DSL 从 sourceSets 获取“allJava”?
- css - 可以将 CSS3 动画文本阴影样式应用于 SVG?
- python - 在对象之后做某事并保存所有相关对象
- c# - 检查 null 或 >0 的简洁方法
- python - 在 numpy 数组上调用 max() 会返回“ValueError:具有多个元素的数组的真值不明确。使用 a.any() 或 a.all()”
- c# - 更改 ASP.NET ReportViewer 工具栏高度
- amazon-web-services - 从 S3 超时流式下载
- javascript - 验证 google reCaptcha 时输入响应和密码无效