IIS URL重写不起作用 - 404错误

时间:2014-07-11 07:22:37

标签: .net iis url-rewriting rewrite

我正在使用IIS7中的URL重写功能。我在端口80上设置了一个网站,其中包含一些URL重写规则。

第一条规则需要指向端口8090上的Web应用程序,另一条规则需要指向端口8091上的Web应用程序。

需要配置规则以便:

  1. http://localhost/重写为http://localhost:8090
  2. http://localhost/test重写为http://localhost:8091
  3. 以下是我正在使用的规则:

    <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错误。

2 个答案:

答案 0 :(得分:0)

我的确最终按要求运行。以下是在端口80上托管的默认网站上使用的web.config文件。 这样我就可以浏览http://my.domain.com/test1并获取http://localhost: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>

答案 1 :(得分:0)

尝试安装“应用程序请求路由”扩展并对其进行配置。

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

相关问题