MediaWiki URLs: Short, Clean and Beautiful

Search Engine love short and clean URLs. Learn how to change default MediaWiki URLs into short URLs while keeping the default URLs also functional. The solution works using .htaccess and LocalSettings.php files.

I run several websites which are based on MediaWiki platform. MediaWiki does provide the option of having beautiful, clean and short URLs but a couple of my earliest MediaWiki websites  did not use pretty addresses simply because I was too lazy and was a bit confused while reading the relevant tutorial given in the MediaWiki help. Lately, I decided to finally make changes in these two websites and implement short URLs.

A typical, long, ugly (and default) MediaWiki URL:

Beautified version of this URL:

Search engines love beautiful URLs which hide the technical details (like parameters and values attached with URL strings).

At first, I was wary that this beautification of URLs might harm websites’ Google ranking because my websites have been there on Internet for more than five years. And in fact it is always better not to change a URL once it is created. But by using redirection through .htaccess file we can safely make these changes without greatly harming search engine rankings.

Cherry on the top is that it is very easy and straightforward to implement short URLs. Here is what you need to do (please note that these instructions are for the MediaWiki installations running on Apache server only):

Add the following code to .htaccess file:

RewriteEngine On



RewriteRule ^(.*)$ %{DOCUMENT_ROOT}/MW-DIRECTORY/index.php [L]

Replace MW-DIRECTORY with the name of directory wherein you have installed MediaWiki (i.e. the directory which contains MediWiki files and folders like extensions, cache, maintenance, skins etc.)

Where to put .htaccess?

The .htaccess file should be placed in the MediaWiki installation directory.

Now add the following code in LocalSettings.php

$wgScriptPath       = “/MW-DIRECTORY“;

$wgScriptExtension  = “.php”;

$wgArticlePath = “{$wgScriptPath}/$1″;

$wgUsePathInfo = true;

Replace MW-DIRECTORY with the MediaWiki installation directory. Your LocalSettings.php file might already contain the first two lines of the code given above. If these lines are already present –just add the second and third line right below the existing lines.

And that’s it! Now your old-and-long-and-ugly URLs will also work because .htaccess will redirect old URLs to the requested page.


  1. m says

    Thank you so much! I just killed hours trying to figure this out. The mediamiki wiki is horrible. This worked like a charm!

Leave a Reply

Your email address will not be published. Required fields are marked *