c# - 在 web.config 中使用 <rewrite> 重定向

标签 c# .net iis

我正在使用以下 web.config 配置将 URL 重定向到新的目标 URL,但在页面加载期间它未按预期工作,

<rewrite>
    <rules>
        <rule name="Benefits to maxxia redirect" stopProcessing="true">
            <match url="http://website1.com/page/calculate" />
            <action type="Redirect" url="https://website2.com/page/package" />
        </rule>
    </rules>
</rewrite>

请让我知道我在这里缺少什么。

最佳答案

match URL 是一个正则表达式,仅匹配 URL 的路径,不包括域名或协议(protocol)。

<rewrite>
    <rules>
        <rule name="Benefits to maxxia redirect" stopProcessing="true">
            <match url="^page/calculate" />
            <action type="Redirect" url="https://website2.com/page/package" />
        </rule>
    </rules>
</rewrite>

另一方面,重定向 URL 可以是绝对的,也可以是相对的,因此您的示例很好。

可以使用条件来匹配 URL 的域名或协议(protocol)部分,如 shown in this post 。例如,要将 http://authoring.mjleague.com.au/calculator 重定向到 http://iotg.mjleague.com.au/calculator:

<rewrite>
    <rules>
        <rule name="Calculator redirect" stopProcessing="true">
            <match url="^calculator" />
            <conditions>
                <add input="{HTTP_HOST}" pattern="authoring.mjleague.com.au" />
            </conditions>
            <action type="Redirect" url="http://iotg.mjleague.com.au/calculator" />
        </rule>
    </rules>
</rewrite>

引用:

关于c# - 在 web.config 中使用 <rewrite> 重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48745955/

相关文章:

c# - WebApi OData 即使在设置 MaxTop 后,已超过 Top 查询的 '0' 限制

c# - 当我编辑代码时 ASP.NET 没有任何变化

Asp.NET Web API - 405 - 不允许用于访问此页面的 HTTP 动词 - 如何设置处理程序映射

c# - 将 Button 的可见性绑定(bind)到 ViewModel 中的 bool 值

C# 随机(长)

c# - Azure Blob 触发函数存储帐户连接

c# - web.config 中的 enforceFIPSPolicy 标志似乎不适用于 Web 应用程序

c# - 非顺序列表绑定(bind)不起作用

c# - FileHelpers .NET 库的最新生产就绪版本是什么?它在哪里?

asp.net - IIS 10 Express 性能问题