简体   繁体   English

IIS 重写根目录下的 ARR 子文件夹和主站点 URL

[英]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.我有几个使用 ARR 设置的站点,它们可以正常工作,但基本 URL 除外,它仍应继续指向旧版应用程序。

It should resolve to the following:它应该解决以下问题:

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.我认为我匹配的 URL 正则表达式是可疑的。

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>

It seems that when you request url www.mysite.com/ , it is considered as directory, so it doesn't match the condition <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> .似乎当您请求 url www.mysite.com/时,它被视为目录,因此它不符合条件<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />

If there aren't any directories when your application running, I think you can remove the second condition <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> in " Reverse Proxy to Legacy App " rule directly.如果您的应用程序运行时没有任何目录,我认为您可以<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />第二个条件直接地。 And then it can implement your requirement.然后它可以实现您的要求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM