Nofollow with a bounce-URL

This is a simple (“simple” hah, it’s pretty complex for a simple annotation) implementation of a bounce URL for adding rel=nofollow support to a static HTML site. (More on other nofollow approaches)


We’ll modify 3 things:

  • Add a /nofollow/ URL which redirects as appropriate
  • Add the /nofollow/ URL to the site’s robots.txt.
  • Modify the render-link.html code to swap in the rel=nofollow

Passing mechanism: We’ll use URL anchors (/folder/page#anchor) to pass the destination URL. This has the advantage of allowing the bounce URL to be cached.

Protection: We want to avoid that others use the bounce URL for nefarious purposes (redirect to malware / phishing). My simple protection is to check the referrer. If the referrer is not from here, then just show the link and let the user click.

Redirection: We’ll use JavaScript to do a simple redirect.

Caption: rough diagram of the setup (slide)

Bounce URL

You can check out the bounce URL at /nofollow/. The main part is a snippet of HTML + JavaScript. Here’s the Gist.

The functionality is basically:

  • Check if the target URL is an external link (starts with ‘http://’ or ‘https://')
  • Check if referrer is on this site
  • If so, redirect
  • If not, display a nofollow link for the user to click on


My robots.txt is a bit … long-winded. The line I added was:

user-agent: *
disallow: /nofollow/

The disallow directive blocks crawling of this URL. It doesn’t block indexing. That doesn’t matter for us.

I extended my render-link.html with this:

{{- if strings.HasPrefix $linkurl "/nofollow/#" }} 
    {{- $relval = printf "%s %s" $relval "nofollow" }}
    {{- $urlparts := split $linkurl "#" -}}
    {{- $linkurl = index $urlparts 1 }}
{{- end -}}

Here’s the full file


No changes expected:

With nofollow expected:

Edge cases:

Comments / questions

There's currently no commenting functionality here. If you'd like to comment, please use Twitter and @me there. Thanks!

Tweet about this - and/or - search for latest comments / top comments

Related pages