【问题标题】:IIS URL Rewrite for redirect to FQDN用于重定向到 FQDN 的 IIS URL 重写
【发布时间】:2023-03-04 18:53:01
【问题描述】:

我正在尝试找出完成以下任务的最佳 URL 重写规则。

http://intranet/sites/default.aspx rewrite to http://intranet.domain.com/sites/default.aspx

http://intranet rewrite to http://intranet.domain.com

同样在 IIS 中,该 Web 应用程序的 URL 绑定设置为“内联网”

希望这是有道理的。有人可以帮忙改写规则吗?

【问题讨论】:

  • 到目前为止你有没有尝试过?
  • 是的,似乎没有任何效果,我必须承认我以前没有做过很多重写。我过去所做的唯一 URL 重写是请求 uri 重定向。
  • 所以规则应该重写任何请求的路径还是只重写sites/default.aspx?
  • 不,intranet* 到 intranet.domain.com* 意味着任何深层 URL 都应该重定向。

标签: iis url-rewriting rewrite


【解决方案1】:

这是我会使用的规则:

<rule name="Intranet redirect" stopProcessing="true">
    <match url="(.*)" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="^intranet$" />
        <add input="{HTTPS}" pattern="^OFF$" />
    </conditions>
    <action type="Redirect" url="http://intranet.domain.com/{R:0}" />
</rule>

它将匹配主机上任何请求的路径 (url="(.*)") 完全命名为 http://intranetpattern="^intranet$" 并且 https 已关闭)并将其重定向到 http://intranet.domain.com/{R:0}(其中 {R:0} 是一个返回包含所请求的任何路径的引用)。

【讨论】:

  • 这行得通!我错过了模式末尾的 $,我认为可能导致重定向循环。感谢您的宝贵时间。
猜你喜欢
  • 2019-02-11
  • 1970-01-01
  • 2018-02-19
  • 2011-01-16
  • 1970-01-01
  • 2016-10-10
  • 1970-01-01
  • 2011-08-07
  • 2015-01-29
相关资源
最近更新 更多