在web中编写一个重定向规则.在asp.net应用程序中配置

本文关键字:规则 重定向 asp net 配置 应用程序 一个 web | 更新日期: 2023-09-27 18:03:52

我在一个网站上有一个帮助部分,现在我希望它重定向到另一个地方。站点的其余部分应该保持不变,这意味着只有帮助部分/内容应该使用户转到另一个站点:

device.domain.net/collection/hgkhghj应返回device.domain.net/collection

我可以有任何地方的hgkhghj。如果我写device.domain.net/collection,那么它应该返回device.domain.net/collection

 <rule name="Help Redirect" stopProcessing="true">            
            <match url="(.*)/collection(.*)" ignoreCase="true" />
            <action type="Redirect" url="http:/device.domain.net" appendQueryString="false" redirectType="Permanent" />
          </rule>

,但目前正在返回device.domain.net。

我想再做一个规则,如果我输入device.domain.net/gcfhgg,那么它应该返回到device.domain.net。

<rule name="Help Redirect" stopProcessing="true">            
        <match url="(.*)" ignoreCase="true" />
        <action type="Redirect" url="http://device.domain.net" appendQueryString="false" redirectType="Permanent" />
      </rule>

在web中编写一个重定向规则.在asp.net应用程序中配置

对于您的第一条规则,您可以使用以下内容(假设它在同一域中):

<rule name="Help Redirect" patternSyntax="ECMAScript" stopProcessing="true">
  <match url="^collection/(.*)" />
  <action type="Redirect" url="collection" appendQueryString="false" redirectType="Permanent" />
</rule>

如果这是在另一个域中,你也需要安装ARR。你的第二条规则更复杂,因为它看起来好像你只在点击404页面时才试图执行重定向。这是我从未使用重写规则做过的事情。是否有理由这样做,而不是显示自定义404页面?