添加使用IIS URL重写模块的出站规则到HTML标记属性 [英] Adding an attribute to an HTML tag using IIS Url Rewrite module outbound rule

查看:452
本文介绍了添加使用IIS URL重写模块的出站规则到HTML标记属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个相对=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}&quot; ref=&quot;nofollow" />
        </rule>
    </outboundRules>

这篇关于添加使用IIS URL重写模块的出站规则到HTML标记属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆