Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
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.
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.
- 16 Jun 09 | 0.1 | Initial release
- 23 Jun 09 | 0.11 | Fixed callback point to play nicely with gbp_permanent_links (thanks pieman/graeme)
- 29 Aug 09 | 0.2 | Uses TXP 4.2.0’s txp_die callback ; also issues a 301 redirect now (both thanks wet)
- 17 Sep 09 | 0.21 | HTML fallback kludge for browsers/server environments that don’t honour the header() for some reason (thanks the blue dragon)
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. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Online
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
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. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Online
Re: smd_short_url: tiny/canonical URLs
Patrick.
Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.
Offline
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. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Online
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
Re: smd_short_url: tiny/canonical URLs
Stef, changing register_callback
did the trick perfectly – no need to change plugin prios. Magic.
Offline
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. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Online
Re: smd_short_url: tiny/canonical URLs
Two things spring to mind:
- 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 intercept404
(and some other) stati and redirect to the canonical URL then:register_callback('smd_short_url', 'txp_die', 404);
- I’m not quite sure if
302
is the proper HTTP status. Maybe301
would fit better (I know who brought302
onto the table in the first place)
Offline
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. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Online
Re: smd_short_url: tiny/canonical URLs
A brief call for help: please would anybody who is running Textpattern in either of the following environments consider testing smd_short_url:
- a sub-directory
- a multi-site setup under 4.2.0/SVN (use v0.2 of the plugin for this — see first post)
I have a suspicion the plugin needs some massaging to work properly in both the above circumstances, so any feedback on the success or otherwise, along with any diagnosticy output, would be much appreciated. Editing the first few lines of the plugin code to read:
$urlparts = parse_url(hu);
dmp($urlparts);
$re = '#^'.$urlparts['path'].'([0-9].*)#';
dmp($re);
$have_id = preg_match($re, $_SERVER['REQUEST_URI'], $m);
dmp($m);
exit;
and posting / mailing me any output would really help as well. Thanks in advance!
Last edited by Bloke (2009-09-15 07:30:09)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Online
Re: smd_short_url: tiny/canonical URLs
Stef: this plugin is just what I was looking for! Thanks!
Sadly though, I don’t have any Txp installs that fit your test criteria. :-)
Alan Macdougall — http://halfpie.net/
Offline