【问题标题】:IIS Url Rewrite Not Working - 404 ErrorIIS URL 重写不起作用 - 404 错误
【发布时间】:2014-07-11 07:22:36
【问题描述】:

我正在使用 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 错误。

【问题讨论】:

  • 你有没有想过这个问题?我有exact same problem。
  • 您可以在下面找到我的解决方案。希望这会有所帮助。

标签: .net iis url-rewriting rewrite


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    我确实按要求完成了这项工作。以下是托管在端口 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>
    

    【讨论】:

    • 谢谢!你的一条规则现在对我很有用
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-26
    • 2011-07-01
    • 2015-01-29
    • 1970-01-01
    • 2017-11-24
    相关资源
    最近更新 更多