我正在使用以下 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/