简体   繁体   中英

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

I am required to add a rel="nofollow" attribute to all <a> tags whose href attribute value matches a defined pattern.

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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