如何创建重写规则以将 POST 请求从两个地址重定向到 Microsoft IIS 10 中的“http://localhost/anpr/”?

发布时间:2021-03-08 15:18

我想将大华 ANPR 相机的两个 POST 请求重定向到 Microsoft IIS 中的一个脚本。我想将 POST 请求从“http://localhost/NotificationInfo/KeepAlive”和“http://localhost/NotificationInfo/TollgateInfo”重定向到“http://localhost/anpr/”。我在主配置文件“C:\inetpub\wwwroot\web.config”中创建了规则:

<rules>
    <rule name="NotificationInfo/TollgateInfo" patternSyntax="ECMAScript">
        <match url="(.*)/NotificationInfo/TollgateInfo" ignoreCase="false" />
        <action type="Rewrite" url="{R:1}/anpr/" appendQueryString="false" logRewrittenUrl="true" />
    </rule>
    <rule name="NotificationInfo/KeepAlive">
        <match url="(.*)/NotificationInfo/KeepAlive$" />
        <action type="Rewrite" url="{R:1}/anpr/" logRewrittenUrl="true" />
    </rule>
    <rule name="NotificationInfo/TollgateInfo/" patternSyntax="ECMAScript">
        <match url="(.*)/NotificationInfo/TollgateInfo/" ignoreCase="false" />
        <action type="Rewrite" url="{R:1}/anpr/" appendQueryString="false" logRewrittenUrl="true" />
    </rule>
    <rule name="NotificationInfo/KeepAlive/">
        <match url="(.*)/NotificationInfo/KeepAlive/$" />
        <action type="Rewrite" url="{R:1}/anpr/" logRewrittenUrl="true" />
    </rule>
</rules>

IIS 10 为“http://localhost/NotificationInfo/KeepAlive”和“http://localhost/NotificationInfo/TollgateInfo”返回错误“HTTP 404.0 — 未找到”。地址“http://localhost/anpr/”有效。 “anpr”是一个带有脚本“index.php”的文件夹。我做错了什么?如何进行这种重定向?如何执行重写规则以从“http://localhost/NotificationInfo/KeepAlive”和“http://localhost/NotificationInfo/TollgateInfo”重定向到“http://localhost/anpr/”?你能帮我吗?

回答1

您的网址有问题,您可以尝试以下规则:

  <rule name="test" stopProcessing="true">
      <match url="^NotificationInfo/(.*)$" />
      <action type="Redirect" url="http://localhost/anpr" />
  </rule>

enter image description here