Mobile Number Tracker
Trace Mobile Number Earn Money Online

MediaWiki URLs: Short, Clean and Beautiful

Samyak Lalit | November 23, 2012 (Last update: September 22, 2017)

Samyak Lalit is an Indian author and disability rights activist. He is the principal author and founder of projects like TechWelkin, WeCapable, Viklangta, Kavita Kosh among many others.

I run several websites which are based on MediaWiki platform. MediaWiki does provide the option of having short URLs that look much cleaner and therefore beautiful. A couple of my earliest MediaWiki websites  did not use pretty URLs 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 my websites and implement short URLs. MediaWiki short URLs hide the index.php?title= part of the web address. Shorter URLs are easier to read and easier to remember. These web addresses are great especially for MW websites that use non-Latin character sets.

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

…and here is Short MediaWiki URL: clean and pretty:

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 my website’s Google and traffic ranks because my websites have been there in the massive world of 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):

STEP 1: 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.

STEP 2: 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.

Once this is done, and if your MediaWiki site is working too slow, you may also want to see my tutorials on how to improve MediaWiki performance.

Thank you for using TechWelkin. Please let me know what you think!


12 responses to “MediaWiki URLs: Short, Clean and Beautiful”

  1. Jorge says:

    It worked!
    Thank you very much.

  2. drX says:

    hi there,

    i have a .wiki domain. does this work if i have mediawiki installed in the root?

    • Lalit Kumar says:

      Although the purpose of creating .wiki domain names is to put wiki based websites on them, but it is not binding. You can use any software on a .wiki domain name to develop your website. You can install MediaWiki in root or under any subdirectory. It’s up to your choice of site structure.

  3. German says:

    Works great. Thanks for the straightforward instructions. I implemented this config and both the long and short URLs work.

    What would need to be added if you wanted to redirect the long URLs to the short URLs?

  4. John Doe says:

    Note that if you get an error, use Straight Quotes (not curly quotes).

  5. Rosewar says:

    Thank you, for the post, I do have a question, I like Hyphens instead of Underscores, how can I change that in the URL?

    • Lalit Kumar says:

      It might require changes in the MediaWiki source code. And that is not advisable because such changes may conflict with future versions of MW as well as with the code of extensions.

  6. Mohammad Sjadian says:

    It worked on my website like a charm! Thank you.

  7. elango says:

    Not working in Windows with xampp server. Any solutions?

  8. 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!

  9. Anon says:

    I spent large chunks of the day trying to make this work until I finally came across this article. Thanks!!

Leave a Reply

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