簡體   English   中英

IIS 重寫根目錄下的 ARR 子文件夾和主站點 URL

[英]IIS Rewrite ARR sub folders and main site on root URL

我可能只是遺漏了一些小東西。

我有幾個使用 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>

似乎當您請求 url www.mysite.com/時,它被視為目錄,因此它不符合條件<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />

如果您的應用程序運行時沒有任何目錄,我認為您可以<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />第二個條件直接地。 然后它可以實現您的要求。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM