如何使用web.config将一个网址重定向到另一个网址?

时间:2019-05-09 05:41:41

标签: c# asp.net-mvc web-config

我想将https://www.test.com/flights/economy-class-flights重定向到https://www.test.com/flight-types/economy-class

我尝试了以下类似方法,但没有用。

<rule name="Redirect 1" stopProcessing="true">
    <match url="https://www.test.com/flights/economy-class-flights" />
    <action type="Redirect" url="https://www.test.com/flight-types/economy-class" /></rule>

1 个答案:

答案 0 :(得分:0)

这对我有用。

<rule name="redirect RedirectURL1" stopProcessing="true">
    <match url="^flights/economy-class-flights" ignoreCase="true" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="^(www.)?test.com" />
    </conditions>
    <action type="Redirect" url="/flight-types/economy-class" redirectType="Permanent" />
</rule>