簡體   English   中英

IIS Url 重寫不起作用 - 404 錯誤

[英]IIS Url Rewrite Not Working - 404 Error

我在 IIS7 中使用 URL 重寫功能。 我已經在端口 80 上建立了一個帶有一些 URL 重寫規則的網站。

第一條規則需要指向端口 8090 上的 Web 應用程序,另一條規則需要指向端口 8091 上的 Web 應用程序。

需要配置規則,以便:

  1. http://localhost/重寫為http://localhost:8090
  2. http://localhost/test重寫為http://localhost:8091

這是我正在使用的規則:

<system.webServer>
    <rewrite>
        <rules>
            <clear />
            <rule name="Site2" enabled="true" stopProcessing="true">
                <match url="^.*/test/.*" />
                <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                <action type="Rewrite" url="http://{HTTP_HOST}:8091/{R:0}" />
            </rule>
            <rule name="Site1" enabled="true" stopProcessing="true">
                <match url=".*" />
                <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                <action type="Rewrite" url="http://{HTTP_HOST}:8090/{R:0}" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>

我會提到“Site1”規則正在起作用。 如果我轉到http://localhost/ ,我會看到托管在端口 8090 上的 Web 應用程序。如果我轉到http://localhost/test ,我會看到 404 錯誤。

我確實按要求完成了這項工作。 以下是我在端口 80 上托管的默認網站上使用的 web.config 文件。這允許我瀏覽到http://my.domain.com/test1並獲取托管在http://上的網站本地主機:8093/test1

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <httpRedirect enabled="false" destination="https://my.domain.com" exactDestination="true" />
        <rewrite>
            <rules>
                <clear />
                <rule name="Redirect to correct test1 address" stopProcessing="true">
                    <match url="^test1$" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                    <action type="Redirect" url="http://my.domain.com/test1/" />
                </rule>
                <rule name="Redirect to correct test2 address" stopProcessing="true">
                    <match url="^test2$" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                    <action type="Redirect" url="http://my.domain.com/test2/" />
                </rule>
                <rule name="Redirect to correct test3 address" stopProcessing="true">
                    <match url="^test3$" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                    <action type="Redirect" url="http://my.domain.com/test3/" />
                </rule>

                <rule name="Reverse Proxy to test1" stopProcessing="true">
                    <match url="^test1/*(.*)" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                    <action type="Rewrite" url="http://localhost:8093/test1/{R:1}" />
                </rule>
                <rule name="Reverse Proxy to test2" stopProcessing="true">
                    <match url="^test2/*(.*)" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                    <action type="Rewrite" url="http://localhost:8093/test2/{R:1}" />
                </rule>
                <rule name="Reverse Proxy to test3" stopProcessing="true">
                    <match url="^test3/*(.*)" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                    <action type="Rewrite" url="http://localhost:8093/test3/{R:1}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

嘗試安裝“應用程序請求路由”擴展並進行配置。

https://www.iis.net/downloads/microsoft/application-request-routing

暫無
暫無

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

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