【问题标题】:IIS URL Rewrite Service1.svc to apiIIS URL 将 Service1.svc 重写为 api
【发布时间】:2021-07-14 12:56:03
【问题描述】:

我正在尝试使用 IIS URL Rewrite 来重写:

http://localhost/RESTDemo/Service1.svc/Personshttp://localhost/RESTDemo/api/Persons

我的 Web.config 中有以下配置:

<system.webServer>
    <rewrite>
        <rules>
            <rule name="Change 'Service1.svc' to 'api'" stopProcessing="true">
                <match url="^(.*)/RESTDemo/api/(.*)$" />
                <action type="Rewrite" url="{R:1}/RESTDemo/Service1.svc/{R:2}" logRewrittenUrl="true" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>

当我在 IIS 中运行 测试模式 时,它似乎正在工作

但是当我测试 POST 到 http://localhost/RESTDemo/api/Persons 时,我从 IIS 中得到 404.0 Not Found。然后,当我尝试对 http://localhost/RESTDemo/Service1.svc/Persons 运行相同的 POST 时,它可以工作。

我尝试检查C:\inetpub\logs\LogFiles\W3SVC1 下的日志,但看不到任何有用的信息,即使我设置了logRewrittenUrl="true",我也只能在我的 IIS 日志中看到:

2021-04-20 10:18:48 127.0.0.1 POST /RESTDemo/api/persons - 80 - 127.0.0.1 Apache-HttpClient/4.5.5+(Java/12.0.1) - 404 0 2 1

我的问题是……

  1. 我做错了什么?
  2. 为什么我在日志文件中看不到重写的 URL?

【问题讨论】:

标签: url-rewriting biztalk iis-10


【解决方案1】:

这是因为你的重写规则有问题,你可以试试下面的重写规则:

<system.webServer>
    <rewrite>
        <rules>
            <rule name="Change 'Service1.svc' to 'api'" stopProcessing="true">
                <match url="^(RESTDemo)/api/(.*)$" />
                <action type="Rewrite" url="RESTDemo/Service1.svc/{R:2}" logRewrittenUrl="true" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>

这是我的演示:

【讨论】:

    猜你喜欢
    • 2013-08-16
    • 1970-01-01
    • 1970-01-01
    • 2021-09-20
    • 2011-04-07
    • 1970-01-01
    • 2017-09-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多