如何忽略asp.net中的父URL重定向

时间:2015-10-21 11:44:58

标签: asp.net redirect

我们有一个网站,我们需要重定向某个网站的所有子网址,但不是最高级别,即。

www.domain.com/products/some-product-page重定向到www.domain.com/some-product-page

这一切都很好。但是,我们在www.domain.com/products上有一个页面,此页面正被重定向到网站主页。

我尝试过两种尝试解决此问题的方法。第一种,使用否定忽略顶级/产品网址。但这也会导致其下方的网址被忽略。

<rule name="Redirect Products child pages" stopProcessing="true">
          <match url="^products/(.*)$" />
          <conditions>
            <add input="{PATH_INFO}" pattern="^(/*)/?.*" />
            <add input="{REQUEST_URI}" negate="true" pattern="^products" ignoreCase="true" />
          </conditions>
          <action type="Redirect" redirectType="Permanent"  url="{R:1}" />
        </rule>

我尝试过对这种模式输入的变化,但收效甚微。

我看到的第二种方法是创建一个仅查找/ products / url的规则,并在找到时停止处理规则。但这也与第一种方法具有相同的效果。

<rule name ="Prevent Products page redirect" stopProcessing="true">
          <match url="(.*)" />
          <conditions>
            <add input="{PATH_INFO}" pattern="^/products/" />
          </conditions>
          <action type="None" />
        </rule>

那么我需要为模式添加一些内容,使其忽略所有其他网址,还是我错过了其他内容?

非常感谢。

1 个答案:

答案 0 :(得分:0)

找到我自己的答案。我的第二种方法有效;只需要一点点调整。像这样:

$result