Web.config 重定向

Web.config redirect

我最近重新设计了我们的网站并将其移至新域。我需要做一些重定向,但我在让它正常工作时遇到了一些问题。

我有 200 多个页面需要重定向,我更愿意在一个规则中完成,而不是 200 个。

这是我需要重定向的示例:

www.OldSite.net/store/index.php/store_location

重定向到:

www.NewSite.com/store/page.aspx?code=store

.net url 的粗体部分是我要在新 .com url 中查询和使用的内容。我很难弄清楚如何在 web.config.

中使用通配符 {R:x}s{C:x}s

通过使用以下规则,我已经能够使单个重定向工作:

conditions logicalGrouping="MatchAny" trackAllCaptures="false"

add input="{HTTP_HOST}{REQUEST_URI}" pattern="www.OldSite.net/store/index.php/store_location" /

/conditions

action type="Redirect" url="https://www.NewSite.com/store/page.aspx?code=store" redirectType="Permanent"/*

但我希望有一种更简单的方法可以用一个规则而不是 200 多个来完成这一切。

通过一系列试验和错误(主要是错误 :D),我终于能够获得一条规则来为我完成所有重定向。如果这对其他人有帮助,这是我使用的规则:

rule name="redirect rule" stopProcessing="true"

match url="(.)/(.)_" /

conditions logicalGrouping="MatchAny" >trackAllCaptures="false"

add input="{HTTP_HOST}{REQUEST_URI}" pattern="www.OldSite.net/store/index.php/" /

/conditions

action type="Redirect" url="https://www.NewSite.com/store/page.aspx?code={R:2}" redirectType="Permanent" /

/rule