EllisLab text mark
Advanced Search
     
EE Shortener plugin: Your own short URLs and redirects
Posted: 12 April 2009 12:38 PM
Avatar
Joined: 2006-07-06
54 posts

Hi all,

Following the concerns over TinyURL and other third-party shortening sites, and lots of recent posts about creating our own discoverable short URLs and permanent redirects, I’ve created a plugin that will take care of all this for EE sites (especially those using quite short domain names).

The problem: Twitter users will be all too aware of the spread of confusing shortened URLs - the TinyURL, tr.im and bit.ly stuff. Over the last week, many have written about the problems of such URLs - bad usability, privacy loss, and the reliance on third-party URL-shortening mediators that could disappear at any time. Certainly, its unlikely that third-party short URLs will be around as long as most of the content they link to.

To divorce ourselves from those tools and provide our own short URLs (on any site) we need to:

Provide a meta link element with the rev=“canonical” and rel=“alternate shorter” attributes in the post’s head.
Provide a visible, clickable a link in the post’s body, again with rev=“canonical” and rel=“alternate shorter” as attributes.
Create a permanent redirect to the actual post, at its natural, elongated URL.

At present, only a few big sites (the likes of Flickr, Dopplr, PHP.net) are doing this, but as more sites embrace it, and more bloggers do the same, we’ll eventually have the critical mass, and maybe when we post those big links into Twitter it’ll automatically find the better short URLs we provide. Its worth the effort, however you look at it. There is already a tool that sniffs for your own short links, and even a short link sniffing bookmarklet.

To use, you’ll need to add two plugin tags to your main post (single entry) template, and create a new template group through which the permanent redirects will happen (using a third plugin tag). Its then just a case of amending two parameters, one being to specify the segment where the url_title is displayed in the URL.

Full details and further reading via my blog at (nice short URL) http://colly.com/s/774

Suggested improvements

Stats tracking the number of redirects from a short URL.
Big one: CP extension for Publish/Edit pages to allow use of a word to mask the entry_id when writing, so you could end up with domain.com/s/word.
Validation: currently no validation for missing parameters (won’t break though).

EDIT: Version 1.4 (attached) added 11th June 2009

Forces removal of www from short and destination URLs. Obviously you’ll need to ensure your site(s) can be found with and without “www”.
Also now supports any template path, including use of index.php or a renamed file (although its best to remove those to keep URLs as short as poss).
Also adds rel=“alternate shorter” to the links.
Finally, our man Glen has made the PHP more efficient.
v1.4: fixed a problem that we added in 1.3 that screwed up paths in some cases!

Colly (Simon Collison)

File Attachments
pi.shortener.php.zip  (File Size: 3KB - Downloads: 383)
 Signature 

Erskine Design: http://www.erskinedesign.com

 
Posted: 20 April 2009 05:27 PM   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2007-06-28
175 posts

Great Plugin.. looking forward to seeing your improvements.  I did some tweaking and I am tracking in Google analytics just fine.  Very useful for community type sites.

 Signature 

twitter

 
Posted: 29 April 2009 08:07 PM   [ # 2 ]   [ Rating: 0 ]
Joined: 2008-02-04
9 posts

I’m going to give it a go.  Great post.  My only drawback is that we have a [sort of] long blog URL to begin with.  Lame! (Okay, I’m crossin’ my fingers now for luck! I’m a total hack.)

 
Posted: 17 May 2009 01:26 PM   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2007-06-28
175 posts

Hey Simon,
I recently started using this on a site and I am getting a weird error:

NoticeUndefined indexurl_title in /home/site/public_html/system/plugins/pi.shortener.php on line 99

Warning
Cannot modify header information headers already sent by (output started at /home/site/public_html/system/plugins/pi.shortener.php:99in /home/site/public_html/system/plugins/pi.shortener.php on line 99 

Once I get that fixed I want to forward to different URLs depending on weblog- is there any way we can use the {comment_url_title_auto_path} parameter to redirect?

I think this concept of internal redirects to shorten URLS is going to become standard across major publishing sites.  I love the plugin and think it’s smartly executed.  Let me know if I can help advance it.

David

 Signature 

twitter

 
Posted: 09 June 2009 01:23 PM   [ # 4 ]   [ Rating: 0 ]
Avatar
Joined: 2004-05-14
74 posts

My links are generating wrong in the PHP code portion.  I have PHP on and set to output.

The links are generated on the pages appropriately, but when I click the shortened url The following occurs:

http://www.ffpblog.com/index.php/system/404#47;scrapbook/individual/not_much_to_update 

It looks like all the slashes in the

<?php
{exp
:shortener:redirect template="index.php/scrapbook/individual" entry_id="{segment_2}"}
?> 

are being transformed to ASCII codes instead of being parsed as slashes and somehow the link is being appended to the 404 page.  I don’t understand whats going on there.

Any Help?

 Signature 

Far From Perfect
Broadcasting live from Iraq via High-speed Bytes/Second Internet!

 
Posted: 11 June 2009 07:03 AM   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2006-07-06
54 posts

Hi everyone - sorry for the delay in fixing a couple of path-related bugs. It was all fine in v1.2, but then we broke something in v1.3. For example, the slash in paths is no longer mistakenly converted into an entity. Should all work fine now with any path parameter.

I’ve added v1.4 at the top of this thread - tested and now working fine.

 Signature 

Erskine Design: http://www.erskinedesign.com

 
Posted: 11 June 2009 07:33 AM   [ # 6 ]   [ Rating: 0 ]
Avatar
Joined: 2006-07-06
54 posts
eyevariety - 17 May 2009 05:26 PM

Hey Simon,
I recently started using this on a site and I am getting a weird error:

NoticeUndefined indexurl_title in /home/site/public_html/system/plugins/pi.shortener.php on line 99

Warning
Cannot modify header information headers already sent by (output started at /home/site/public_html/system/plugins/pi.shortener.php:99in /home/site/public_html/system/plugins/pi.shortener.php on line 99 

Once I get that fixed I want to forward to different URLs depending on weblog- is there any way we can use the {comment_url_title_auto_path} parameter to redirect?

I think this concept of internal redirects to shorten URLS is going to become standard across major publishing sites.  I love the plugin and think it’s smartly executed.  Let me know if I can help advance it.

David

HI David,

We just used the plugin on a site that has five article-based weblogs, and we needed (as I’d suggested in my blog write-up) that each blog needs its own redirect template group. Bit clunky.

Myself and the chaps had also thought that a better or more flexible version could use the {comment_url_title_auto_path} parameter, and we’re gonna work on that by amending the plugin’s SQL query. Of course, we know a lot of people don’t properly add paths to the weblog preferences, so they’d need to do that for such a plugin to work. Anyway, we’ll report back once we’ve made it work.

Simon

 Signature 

Erskine Design: http://www.erskinedesign.com

 
Posted: 13 July 2009 02:16 PM   [ # 7 ]   [ Rating: 0 ]
Joined: 2007-07-04
459 posts

How has your comment_url_title_path idea getting on?

 
Posted: 05 September 2009 10:51 AM   [ # 8 ]   [ Rating: 0 ]
Joined: 2007-08-12
98 posts

I’m gonna give this a try, I’d love to encourage that you continue to develop this one.
Thank for sharing.

 
Posted: 05 September 2009 04:58 PM   [ # 9 ]   [ Rating: 0 ]
Avatar
Joined: 2007-06-28
175 posts

Nick’s redirect plugin here supports comment_url_title_path and so much more- worth looking at if you are dabbling in this- I am using it with +1000 requests every 15 minutes without problems.

 Signature 

twitter

 
Posted: 21 December 2009 09:51 PM   [ # 10 ]   [ Rating: 0 ]
Avatar
Joined: 2008-05-26
214 posts

any chance this can be updated for expression engine 2 ?

 
Posted: 22 December 2009 12:00 PM   [ # 11 ]   [ Rating: 0 ]
Avatar
Joined: 2006-07-06
54 posts

I won’t be able to update it until maybe February. My colleague Greg rewrote it for slightly different needs also. Currently testing that on a couple of sites.

Since I wrote the first EE Shortener plugin, a few other people have improved it anyway. You could try http://hivelogic.com/articles/introducing-shrimp/ and see if Dan plans to upgrade that. Just make sure any you use have the important short URL discoverable factor, for use with bookmarklets etc such as http://simonwillison.net/2009/Apr/11/revcanonical/ - that is vital in my opinion.

As I said before, if we do any updates or new versions to the Erskine shortener, we’ll let you know on this thread.

Colly

 Signature 

Erskine Design: http://www.erskinedesign.com

 
Posted: 11 June 2010 09:48 PM   [ # 12 ]   [ Rating: 0 ]
Avatar
Joined: 2007-12-08
88 posts

Great add-on! Is there a way to show just the full URL and not have it linked?

I have some code I use for linking to Twitter, and the short URL won’t work for this because I have to place it inside of an <a href=”“> tag.

Thanks!

 Signature 

BaneyDesign.com   |   Skype: baney.design