【问题标题】:IIS Outbound Rules URL Rewrite Scheme for Anchor Tag Links用于锚标记链接的 IIS 出站规则 URL 重写方案
【发布时间】:2020-07-02 00:20:47
【问题描述】:

我一直在尝试寻找一些关于如何执行 URL 重写的附加信息,其中预期的输出是删除/替换部分 url。

例如,我想确保我的所有锚标记的 href 值都会被修改。

<a class="button" href="https://www.oldgoogle.com" target="_blank">
<a class="button" href="https://www.oldgoogle.com/links" target="_blank">
<a class="button" href="https://www.oldgoogle.com/links/category?dosearch=true" target="_blank">
<a class="button" href="https://oldgoogle.com/nowww" target="_blank">

使得href值变成这样:

<a class="button" href="https://newgoogle.com" target="_blank">
<a class="button" href="https://newoogle.com/links" target="_blank">
<a class="button" href="https://newgoogle.com/links/category?dosearch=true" target="_blank">
<a class="button" href="https://newgoogle.com/nowww" target="_blank">

请注意,我实际上是在 从网址中删除 www,并将 oldgoogle 替换为 newgoogle

这是我迄今为止尝试过的:

<rewrite>
  <outboundRules>
    <remove name="Strip WWW from Anchor Tags" />
    <rule name="Strip WWW from Anchor Tags" preCondition="IsHTML">
      <match filterByTags="A" pattern="^http(s)://www.oldgoogle.com/(.*)" />
      <conditions />
      <action type="Rewrite" value="https://newgoogle.com/{R:1}" />
    </rule>
  </outboundRules>
</rewrite>

感谢您分享解决此问题的任何信息。

附:我们无法修改来自源的链接,因为这些链接都散落在外部文本文件、数据库表和其他源的网络中,并且一些硬编码规则按原样编写链接。所以我唯一的选择是重写应用程序生成和发出的链接。

【问题讨论】:

    标签: url iis url-rewriting iis-7


    【解决方案1】:

    您可以尝试使用以下规则:

    <outboundRules>
                  <rule name="rule1" preCondition="ResponseIsHtml1" stopProcessing="true">
                    <match filterByTags="A" pattern="http(s)://(www.)?oldgoogle.com(.*)" />
                    <action type="Rewrite" value="https://newgoogle.com{R:3}" />
                </rule>
                <preConditions>
                    <preCondition name="ResponseIsHtml1">
                        <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
                    </preCondition>
                </preConditions>
            </outboundRules>
    

    【讨论】:

      猜你喜欢
      • 2019-03-13
      • 1970-01-01
      • 2014-10-27
      • 2014-05-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多