We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

EE Shortener plugin: Your own short URLs and redirects

Development and Programming

Erskine's avatar
Erskine
46 posts
16 years ago
Erskine's avatar Erskine

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)

       
eyevariety's avatar
eyevariety
158 posts
16 years ago
eyevariety's avatar eyevariety

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.

       
bensmithson's avatar
bensmithson
4 posts
16 years ago
bensmithson's avatar bensmithson

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.)

       
eyevariety's avatar
eyevariety
158 posts
16 years ago
eyevariety's avatar eyevariety

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

Notice: Undefined index: url_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:99) in /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

       
medic119's avatar
medic119
52 posts
16 years ago
medic119's avatar medic119

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?

       
Erskine's avatar
Erskine
46 posts
16 years ago
Erskine's avatar Erskine

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.

       
Erskine's avatar
Erskine
46 posts
16 years ago
Erskine's avatar Erskine
Hey Simon, I recently started using this on a site and I am getting a weird error:
Notice: Undefined index: url_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:99) in /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

       
Joobs's avatar
Joobs
362 posts
16 years ago
Joobs's avatar Joobs

How has your comment_url_title_path idea getting on?

       
wecreateyou's avatar
wecreateyou
86 posts
15 years ago
wecreateyou's avatar wecreateyou

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

       
eyevariety's avatar
eyevariety
158 posts
15 years ago
eyevariety's avatar eyevariety

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.

       
adamprocter's avatar
adamprocter
228 posts
15 years ago
adamprocter's avatar adamprocter

any chance this can be updated for expression engine 2 ?

       
Erskine's avatar
Erskine
46 posts
15 years ago
Erskine's avatar Erskine

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

       
AdamBaney's avatar
AdamBaney
65 posts
15 years ago
AdamBaney's avatar AdamBaney

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!

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.