Bloge-ShortUrl

Summary: Get short URLs on your own site
Version: 2009-08-28
Prerequisites: PmWiki 2.2.x
Status: beta
Maintainer: Eemeli Aro
Categories: Administration, Blog, CMS, Links

Description

Given the inherent uncertainty in using external URL shorteners such as tr.im or bit.ly, it's sensible to manage short URLs on your own site—assuming, of course, that the path to your wiki isn't too long to start with. Bloge-ShortUrl will manage this map for you.

Bloge-ShortUrl is a part of Cookbook.Bloge, but may also be used as a standalone recipe.

Installation

  • download bloge-shorturl.phpΔ to your cookbook directory
  • add the following line to your configuration file:
    include_once("$FarmD/cookbook/bloge-shorturl.php");

Usage

The mapping of short URLs to actual page names is kept on the page $ShortUrlPage (by default Site.ShortUrl) where each line defines a mapping code pagename, with codes that consist of numbers (0-9) and lower-case letters (a-z). These codes are automatically generated and added to the list when a page is edited. You can prevent short URLs from being generated for specific pages by defining an array $ShortUrlFilter in the style of MatchPageNames $patterns.

The short URL for a page, if one exists, can be found using a new page variable {$ShortUrl}; this is blank if no short URL exists for the page.

By default Bloge-ShortUrl will take over a (hopefully) non-existing group 'S', such that request for pages such as S.4b will instead be redirected to the corresponding page. Hence a short URL on pmwiki.org could have the form http://pmwiki.org/wiki/s/a1. The group name to use is defined by the variable $ShortUrlGroup, which you may freely set in a configuration file.

For even shorter URLs, web server redirection can be used. For example, with the following Apache directive short URLs on pmwiki.org could have the form http://pmwiki.org/xa1

RedirectMatch ^/x(.*)$ /wiki/S/$1

Note that this kind of mapping will also require you to manually set the value of $ShortUrlPrefix to correspond, for example $ShortUrlPrefix = 'http://pmwiki.org/x'; following the above.

Notes

The Site.ShortUrl page can of course be manually edited to add or modify mappings as required, provided that each short URL consists only of characters from the set 0-9 and a-z.

A page is added to the short URL map when it's edited while the recipe is enabled. When adding a new page, the recipe will assume that Site.ShortUrl contains the highest-numbered code first, and adds 1 to its value until a free code is found. Hence any customized codes should not be placed at the very top of the map.

Short URL auto-discovery is supported by adding a <link rel="shorturl"> tag to the page header. You can disable this by setting $HTMLHeaderFmt['shorturl'] to an empty value.

Bloge-core sets the following default value to the filter array:

$ShortUrlFilter = array('!^Comments\.!', '!-Draft$!');

The internal value of a code makes use of PHP's base_convert function, hence the limitation to only using the characters 0-9 and a-z. This means that two-character codes will take you to 1296 pages and three characters to 46656. If you get to that point you probably shouldn't be using this recipe anymore.

Release notes

See also

Contributors

Comments

See discussion at Bloge-ShortUrl-Talk

User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.