Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jamie Mansel 10 posts 30 karma points
    Dec 11, 2012 @ 13:22
    Jamie Mansel
    0

    Automatically add rel="nofollow" to external links

    Hi all,

    As the title suggest, I need a solution that will automatically add the attribute 'rel="nofollow"' to any external links that are added to an Umbraco site by a user.

    The site is running in version 4.0.2.1 and a solution for this version would be preffered.

    Could this be accomplished using Xslt or maybe a user control?

    I thought about the following:

    ...
    <xsl:template match="a" mode="html" priority="1">

    <!-- Check if external -->
    <xsl:if test="[check if href is from external domain]">
      <a rel="nofollow">
          <xsl:apply-templates select="* | @* | text()" mode="html"/>
        </a>
      </xsl:if>
    </xsl:template>
    But I think running this for the entire site would be very inefficient.
    Any ideas?
    Thanks,
    Jamie

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Dec 11, 2012 @ 13:41
    Chriztian Steinmeier
    0

    Hi Jamie,

    Depends very much on how you're rendering stuff (but you probably know that).

    Your proposed solution would work for all Richtext Editors IF you we're using something like this approach for those. (Problem is they're saved as plain text, so you can't use XSLT like that out of the box).

    For links created with the URL Picker or similar, you could use a similar approach (using an include file with a "link"-moded template for building links...)

    But as noted, it's not possible to make sure you catch every single link, unless you know exactly how everything is rendered from your macros/templates etc. 

    /Chriztian 

     

Please Sign in or register to post replies

Write your reply to:

Draft