by Daniel Davies

A little Internet history; once upon a time loads of people used systems like Geocities and other free webhosts. There were no such thing as slugs, and mod_rewrite was considered dangerous (at least according to my lecturers at the time). Webmasters thus wanted easy to remember URLs for their sites and the URL shortening service started to take off. Take a 40 character URL and create a nice 10(ish) character URL.

Then came micro-blogging, i.e. Twitter. With limited characters available to say what you want, sharing longs links was no longer a bit of nuisance, it was impossible. A new breed of trendy funky URL shorteners arrived boasting their APIs and abilities to monitor your click throughs. But it was no longer the webmasters choosing their URL shortening service, it became the choice of the mirco-blogger.

And thus we hit a problem. Lots and lots of links, all going to the same place. A single point of failure, and a virtual impossibility for the conscious webmaster wishing to track their links around the web.

So now there's a new buzz word coming. Its difficult to spell, its implicit (as opposed to explicit, which is always better), and its likely to fail in HTML 5 (Ben Ramsey sums up the problems very well). But none the less, its still a very good idea, in principle. RevCanonical is a system whereby webmasters can define in the header of their site a shortened URL ideal for sharing across the web. Considerate users, people who share links a lot, will no doubt use the bookmarklet provided on the RevCanonical site so that they can share pages with the webmaster's preferred URL and a lot of problems will be eased.

Django App

This blog is now supporting RevCanonical, through a Django app I wrote in an hour on my lunch break. You can download the app for free of course. You'll also need three lines in your settings.py file to make it all work. Change danux with the name of your project obviously. You'll need to check all the files to make sure the import is correct.

TEMPLATE_CONTEXT_PROCESSORS = (
'danux.shorturls.context_processors.short_url',
)
MIDDLEWARE_CLASSES = (
'danux.shorturls.middleware.ShortURLConvert',
)
INSTALLED_APPS = (
'danux.shorturls',
)

Any model with a get_absolute_url() method can register with ShortURL using Django's signals.

from django.db.models.signals import post_save 
from danux.shorturls.models import register_url_signal
post_save.connect(register_url_signal, sender=Article)

Then, to add the correct information to your <head> tag in your base.html.

{% if short_url %}
<link rev="canonical" rel="alternate shorter" href="{{ short_url }}" />
{% endif %}

This will not currently work for SSL enabled sites, simply because I was in a rush. I will revisit this at some point no doubt, or perhaps someone would like to fix it and share it back? You also need the Sites app installed.

Wordpress User?

Try Rob Allen's Wordpress plugin, it does the same.

Talk about RevCanonical and a Django App to make it happen

Got something to say? Leave a comment!

A picture of Dave Walker

re: RevCanonical and a Django App to make it happen

Posted by Dave Walker

You keep adding neat features!

I hadn't even heard of RevCanonical before now...

What would be neat... WP2danux tool :)

Got something to say? Leave a comment!

Contact Daniel…

Request a Quote