Monday, October 6, 2008

MediaWiki Tidy URLs

This article describes how to configure nice URLs on MediaWiki. The wiki page on the topic is rather massive and hard to understand so here are the instructions for Apache2.
Before:
http://my.domain.com/wiki/index.php?title=Main_Page&action=view

After:
http://my.domain.com/wiki/Main_Page/view


Add the following likes at the end of LocalSettings.php. Update $wgScriptPath to reflect you install.
LocalSettings.php
$wgScriptPath = "/wiki";

$wgArticlePath = "$wgScriptPath/$1";

$actions = array('view', 'edit', 'watch', 'unwatch', 'delete','revert', 'rollback', 'protect',
'unprotect','info','markpatrolled','validate','render','deletetrackback','print',
'dublincore','creativecommons','credits','submit','viewsource','history','purge');

foreach ($actions as $a)
$wgActionPaths[$a] = "$wgScriptPath/$1/$a";


Enable the loading of the mod_rewrite.c module.
LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so


Add the following to your httpd.conf or virtual site. Again, replace /wiki as needed.
RewriteCond %{REQUEST_URI} /(view|edit|watch|unwatch|delete|revert|rollback|protect|unprotect|info|markpatrolled|validate|render|deletetrackback|print$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/wiki/(.*)/([a-z]*)$ /wiki/index.php?title=$1&action=$2 [L,QSA]

RewriteCond %{REQUEST_URI} !/wiki/images
RewriteCond %{REQUEST_URI} !/wiki/skins
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/wiki/(.*)$ /wiki/index.php?title=$1 [PT,L,QSA]

No comments: