添加使用IIS URL重写模块的出站规则到HTML标记属性 [英] Adding an attribute to an HTML tag using IIS Url Rewrite module outbound rule
问题描述
我需要一个相对=nofollow
属性添加到所有< A>的
标记的href
属性值定义的模式相匹配。
I am required to add a rel="nofollow"
attribute to all <a>
tags whose href
attribute value matches a defined pattern.
我会认为这是可能的这个使用IIS URL重写模块,采用了自定义标签重写出站规则来赋值给相对
属性。该规则将是这个样子:
I'd thought that it might be possible to do this using the IIS Url Rewrite module, using an outbound rule with a custom tag rewrite to assign the value to the rel
attribute. The rule would look something like this:
<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>
然而,由于现有的标签没有一个相对
属性,有没有对规则匹配这样什么也不会发生。
However, as the existing tags don't have a rel
attribute, there is nothing for the rule to match against so nothing happens.
有人知道,如果它能够添加不使用这种技术存在标签的一个属性
Does anyone know if it is possible to add an attribute that doesn't exists to a tag using this technique?
推荐答案
有是一个使用规则如下图所示存档这一目标的一个取巧的办法,
There is a tricky way to archive this goal using rule like below,
<outboundRules>
<rule name="outbound" stopProcessing="true">
<match filterByTags="A" pattern="(.*)" />
<action type="Rewrite" value="{R:1}" ref="nofollow" />
</rule>
</outboundRules>
这篇关于添加使用IIS URL重写模块的出站规则到HTML标记属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!