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


Given the inherent uncertainty in using external URL shorteners such as or, 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.


  • download bloge-shorturl.phpΔ to your cookbook directory
  • add the following line to your configuration file:


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 could have the form 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 could have the form

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 = ''; following the above.


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



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.