Feature Proposal: Support in TWiki.pm for Shorter URLs, ommiting HomeWeb and WebHome

Motivation

In ShorterUrlCookbook ( Changes to lib/TWiki.pm - for extra shortening ) it is hinted that some code could be add to TWiki.pm to give extra short URLs

Description and Documentation

This proposal is to add a config var, $TWiki::cfg{ShortURLs} that if defined will make autolink topics omit the home topic and even the home web, if defined by the $TWiki::cfg{HomeWebName}, as proposed in CreateHomeWebVariable.

By default TWiki behavior is not changed, but a new bin/configure variable can be set, ShortURLs, that, when set, will make html links created from WikiWords use the short URL form as defined in ShorterUrlCookbook, i.e.
  • omitting the topic name if it is the Home Topic (i.e. the $TWiki::cfg{HomeTopicName} var which defaults to WebHome)
  • also omitting the web name if it is the Home web (i.e. the $TWiki::cfg{HomeWebName} var which defaults to Home)
  • Note that omitting the bin/view prefix is done by setting also the existing TWiki configure var
    $TWiki::cfg{ScriptUrlPaths}{view} = '';
    in =lib/LocalSite.cfg

This supposes that the installation is set up to expand back the short URLs should be complemented by, for instance in apache config adding these rules: (these ones suppose that twiki is at the root of the web site, and no perl extension are needed)

  RewriteEngine on 
  RewriteRule ^/Home/WebHome$ / [R=permanent,L] 
  RewriteRule ^/([A-Z].*)/WebHome$ /$1/ [R=permanent,L] 
  RewriteRule ^/Home/([^/]*)$ /$1 [R=permanent,L] 
  RewriteRule ^/bin/view/(.*)$ /$1 [R=permanent,L] 
  RewriteRule ^/bin/view$ / [R=permanent,L]
  RewriteRule ^/([A-Z][^/]*/.*[^/])$ /bin/view/$1 [PT]  
  RewriteRule ^/([A-Z].*)/$ /bin/view/$1/WebHome [PT]  
  RewriteRule ^/([A-Z][^/][^/]*)$ /bin/view/Home/$1 [PT]  
  RewriteRule ^/$ /bin/view/Home/WebHome [PT]  

Examples

See http://wiki.koalaz.net/ navigate in it and observe the URL:

Impact

Rendering %WHATDOESITAFFECT%
edit

Implementation

See proposal implementation as an attached patch 420-shorturls.diff to TWiki-4.2.0 (apply with patch -p0 <420-shorturls.diff It modifies lib/TWiki.pm lib/TWiki.spec

My working dir for this is availabe on the mercurial repository: http://hg.colas.nahaboo.net/twiki-colas/42-shorturls/

-- Contributors: ColasNahaboo - 27 Jan 2008

Discussion

Colas, I think it would be helpful if you added a declaration of what system paths are assumed in this topic. Specifically, I want to know if your code above assumes that the TWiki installation is in the root or in the typical /twiki subdir. This helps me understand when the given paths should read e.g. /bin/view or /twiki/bin/view. Then I can test this on TWikiVMDebianStable as well!

-- TorbenGB - 12 Feb 2008

Ah, normally if your twiki is installed in /twiki, but you want the URLs at root, I think the rules become:
  RewriteEngine on 
  RewriteRule ^/Home/WebHome$ / [R=permanent,L] 
  RewriteRule ^/([A-Z].*)/WebHome$ /$1/ [R=permanent,L] 
  RewriteRule ^/Home/([^/]*)$ /$1 [R=permanent,L] 
  RewriteRule ^/twiki/bin/view/(.*)$ /$1 [R=permanent,L] 
  RewriteRule ^/twiki/bin/view$ / [R=permanent,L]
  RewriteRule ^/([A-Z][^/]*/.*[^/])$ /twiki/bin/view/$1 [PT]  
  RewriteRule ^/([A-Z].*)/$ /twiki/bin/view/$1/WebHome [PT]  
  RewriteRule ^/([A-Z][^/][^/]*)$ /twiki/bin/view/Home/$1 [PT]  
  RewriteRule ^/$ /twiki/bin/view/Home/WebHome [PT]  

-- ColasNahaboo - 12 Feb 2008

FWIW, i usually have something like this:
Topic revision: r3 - 18 Feb 2012, ColasNahaboo
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy