Very short URLs

Aus Free Software
Zur Navigation springen Zur Suche springen

Normally, a link to a MediaWiki-page is always prefixed with "index.php". The URL for the Main Page might look something like this:


This is of course not so bad, but If you want your MediaWiki to look really professional (with the standard theme, hehe), you might like the URL look like this:


... which looks all so much cleaner.


The solution is to rewrite your URLs using apaches mod_rewrite. You can do this with your local per-directory .htaccess file or in your global server config. If you have a choice, you should always use the global server config, since the performance of that solution is superiour because it requires no disc access.

The solution presented below is only tested in the global server config, but should work with only minor adjustments in your local .htaccess as well.


First, you have to set the appropriate RewriteRules in place:

RewriteCond %{REQUEST_URI} !^/(index.php|skins|images|favicon.ico|~.*)
  RewriteRule ^/(.*)$ /index.php/$1 [L]

This way, a request to /Main_Page will be rewritten to a request to /index.php/Main_Page, but a request to /skins/foo_bar will not be rewritten at all. Also note the "~.*" in the alternatives that of course allow you to still use the users public_html dirs.


The LocalSettings.php of the Wikis look like this:

$wgScriptPath       = "";
$wgScript           = "$wgScriptPath/index.php";
$wgRedirectScript   = "$wgScriptPath/redirect.php";
$wgArticlePath      = "$wgScriptPath/$1";
$wgStylePath        = "$wgScriptPath/skins";
$wgStyleDirectory   = "$IP/skins";
$wgLogo             = "$wgStylePath/common/tubasis_a.png";
$wgUploadPath       = "$wgScriptPath/images";
$wgUploadDirectory  = "$IP/images";