簡體   English   中英

IIS從子域重定向到路徑

[英]IIS redirect from subdomain to path

假設我有這樣的真實子域。

test.example.com,是否可以為iis編寫一條規則以將子域重定向到test.example.com/SomeStaticPage.html

該規則應適用於多級子域,即 應將test.aaa.bbb.example.com重定向到test.aaa.bbb.example.com/SomeStaticPage.html

使用URL重寫非常容易,實際上,我想知道是否沒有完全了解需求。 (每個域需要不同的靜態頁面嗎?還是在沒有指定默認頁面的情況下,僅保留主機名的同時重定向到相同的“ SomestaticPage.html”?)

這樣的簡單規則可以解決您的問題:

<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="RedirectToSomeStatic" stopProcessing="true">
                    <match url="^$" />
                    <action type="Redirect" url="/SomeStaticPage.html" />
                </rule>
            </rules>
        </rewrite>
    <system.webServer>
</configuration>

現在,如果您正在尋找一種更完整的解決方案,該解決方案允許您基於主機名指定頁面,則可以使用重寫映射,在其中添加應重定向的主機名以及它們應轉到的頁面。 例如,以下規則將檢查他們是否正在請求“ /”,並且主機名在重寫映射中,並將使用該頁面進行重定向,如果它不在列表中,則它將不執行任何操作:

<configuration>
<system.webServer>
    <rewrite>
        <rules>
            <rule name="RedirectToSomeStatic" stopProcessing="true">
                <match url="^$" />
                <action type="Redirect" url="{C:0}" />
                <conditions>
                    <add input="{HostMap:{HTTP_HOST}}" pattern=".+" />
                </conditions>
            </rule>
        </rules>
        <rewriteMaps>
            <rewriteMap name="HostMap">
                <add key="test.example.com" value="/SomeStaticForTestExample.html" />
                <add key="test.a.b.c.example.com" value="/SomePageForTestABC.html" />
            </rewriteMap>
        </rewriteMaps>
    </rewrite>
</system.webServer>

暫無
暫無

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

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