【问题标题】:IIS Rewrite ARR sub folders and main site on root URLIIS 重写 ARR 子文件夹和根 URL 上的主站点
【发布时间】:2021-08-17 10:12:08
【问题描述】:

我可能只是错过了一些小东西。

我有几个使用 ARR 设置的网站,它们都可以正常工作,但基本 URL 仍应继续指向旧版应用程序。

它应该解决以下问题:

我了解重写规则是按照放置顺序检查的,因此我将旧版应用程序放在最后。我认为我匹配的 URL 正则表达式是可疑的。

这甚至可能吗?非常感谢您的帮助。

<?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>

【问题讨论】:

标签: regex http iis url-rewriting arr


【解决方案1】:

好像当你请求urlwww.mysite.com/时,它被认为是目录,所以它不符合条件&lt;add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /&gt;

如果您的应用程序运行时没有任何目录,我认为您可以直接删除“Reverse Proxy to Legacy App”规则中的第二个条件&lt;add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /&gt;。然后它可以实现您的要求。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-11-08
    • 1970-01-01
    • 2023-04-07
    • 1970-01-01
    • 2014-08-04
    • 1970-01-01
    • 1970-01-01
    • 2017-02-13
    相关资源
    最近更新 更多