繁体   English   中英

使用IIS网址重写模块出站规则将属性添加到HTML标记

[英]Adding an attribute to an HTML tag using IIS Url Rewrite module outbound rule

我需要向其href属性值与定义的模式匹配的所有<a>标签添加rel="nofollow"属性。

我以为可以使用IIS Url Rewrite模块,使用带有自定义标记重写的出站规则将值分配给rel属性来执行此操作。 该规则如下所示:

<rule name="Shop url rewrite" preCondition="ResponseIsHtml">
    <match filterByTags="CustomTags" customTags="Anchor rel attribute" pattern="^$" />
    <action type="Rewrite" value="nofollow" />
</rule>
<preConditions>
    <preCondition name="ResponseIsHtml">
        <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
    </preCondition>
</preConditions>
<customTags>
    <tags name="Anchor rel attribute">
        <tag name="a" attribute="rel" />
    </tags>
</customTags>

但是,由于现有标签没有rel属性,因此没有任何规则可以匹配,因此没有任何反应。

有谁知道使用这种技术是否可以向标签添加不存在的属性?

有一种使用以下规则来存档此目标的技巧,

<outboundRules>
        <rule name="outbound" stopProcessing="true">
            <match filterByTags="A" pattern="(.*)" />
            <action type="Rewrite" value="{R:1}&quot; ref=&quot;nofollow" />
        </rule>
    </outboundRules>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM