Textpattern Forum

You are not logged in. Register | Login | Help

#1 2009-06-16 20:58:30

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 5,909
Website

smd_short_url: tiny/canonical URLs

Allow your visitors to use just the article ID in the URL. Optionally output a canonical <link> tag that uses said short URL too.

Written in response to Sam’s request, using wet’s code.

Download v0.21

Revision history
————————

All available versions and changes are listed here. Each entry indexes the relevant post(s) in the threads to learn about the features.

Last edited by Bloke (2009-10-19 10:25:34)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern.

Txp Builders – finely-crafted code, design and Txp

Offline

#2 2009-06-18 08:46:54

pieman
Member
From: Bristol, UK
Registered: 2005-09-22
Posts: 491
Website

Re: smd_short_url: tiny/canonical URLs

Killer idea Steph – another timely addition to the toolset.

The only problem I can see with it is that it doesn’t appear to play nicely with gbp_permanent_links (I’m using 1.3) – it just rewrites the URL according to the Txp prefs.

I’m not sure which plugin would need to be updated, but until they’re compatible, smd_short_url is a no go for me.

Offline

#3 2009-06-18 09:40:28

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 5,909
Website

Re: smd_short_url: tiny/canonical URLs

pieman wrote:

The only problem I can see with it is that it doesn’t appear to play nicely with gbp_permanent_links

No, you’re right it won’t. It just generates a stock TXP url and forwards the page to that. I guess gbp_permanent_links doesn’t get called again after a redirect. Have you tried putting smd_short_url at a higher priority (e.g 4) so it is called first, thus giving gbp_ a chance to rewrite the url a second time? Long shot, but it might work.

I’ll drop Graeme a line and see if he can tell me the best way to make the plugins play in the same sandpit without throwing sand in each others’ eyes.

Last edited by Bloke (2009-06-18 09:40:52)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern.

Txp Builders – finely-crafted code, design and Txp

Offline

#4 2009-06-18 13:01:34

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,018
Website

Re: smd_short_url: tiny/canonical URLs

Sorry Stef,

@pieman :

Did you try robert’s solution within your error_default page ?


Patrick.
Txp Tricks & Tips by french users : http://txp-fr.net | G+
Alison: a CSS Grid tool for all browsers

Offline

#5 2009-06-18 15:28:54

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 5,909
Website

Re: smd_short_url: tiny/canonical URLs

pieman

I got a reply from Graeme. Give this a whirl: go into smd_short_url and change the first line to this:

register_callback('smd_short_url', 'textpattern');

Then see if it works with gbp_permanent_links. Also try adjusting the plugin priorities. It may be that gbp_permanent_links has to be first I don’t know. If any combination of change to plugin code and order of execution works, please let me know so I can supply the option to make it work with gbp_permanent_links.

Also give Pat64’s idea a go. If that works I can try and make the plugin optionally hook into the 404 page as well.

Thanks in advance.

Last edited by Bloke (2009-06-18 15:30:58)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern.

Txp Builders – finely-crafted code, design and Txp

Offline

#6 2009-06-22 12:44:58

pieman
Member
From: Bristol, UK
Registered: 2005-09-22
Posts: 491
Website

Re: smd_short_url: tiny/canonical URLs

Oops, I forgot to subscribe to this topic. How rude.

Thanks for the ideas – I’ll try them out.

Offline

#7 2009-06-23 15:09:31

pieman
Member
From: Bristol, UK
Registered: 2005-09-22
Posts: 491
Website

Re: smd_short_url: tiny/canonical URLs

Stef, changing register_callback did the trick perfectly – no need to change plugin prios. Magic.

Offline

#8 2009-06-23 15:22:45

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 5,909
Website

Re: smd_short_url: tiny/canonical URLs

pieman wrote:

Stef, changing register_callback did the trick perfectly

Excellent, thanks for testing. In which case, consider the plugin updated to v0.11


The smd plugin menagerie — for when you need one more gribble of power from Textpattern.

Txp Builders – finely-crafted code, design and Txp

Offline

#9 2009-06-26 07:31:54

wet
Developer
From: Lenzing, Austria
Registered: 2005-06-06
Posts: 3,108
Website

Re: smd_short_url: tiny/canonical URLs

Two things spring to mind:

  1. Trying to map a short to a canonical URL with every 'textpattern' event will result in approximately 99% energy waste as most requests will not go to any short URL. Thus, I’ve added a ‘txp_die’ event for TXP 4.2.0 which lets you easily intercept 404 (and some other) stati and redirect to the canonical URL then: register_callback('smd_short_url', 'txp_die', 404);
  2. I’m not quite sure if 302 is the proper HTTP status. Maybe 301 would fit better (I know who brought 302 onto the table in the first place)

Offline

#10 2009-06-26 08:28:57

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 5,909
Website

Re: smd_short_url: tiny/canonical URLs

wet wrote:

Two things spring to mind <snip>

Fabulous. Thank you very much, sir. I’ll fix the plugin ready for release alongside 4.2.0. In fact, that callback is going to come in very handy for a few other projects I’m working on.

And you’re right about the status code. I should have read up on the difference between 301 and 302 before blindly implementing it. Thanks for the correction.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern.

Txp Builders – finely-crafted code, design and Txp

Offline

Board footer

Powered by FluxBB