MediaWiki: how to handle pretty URLs under IIS with web.config and URL Rewrite module

How to enable the WikiEditor in your own MediaWiki

In case you installed MediaWiki on IIS, you might want to use pretty URLs instead of ugly ones. To quickly understand what we’re talking about, here’s an example of pretty URL:


and here’s an ugly one:


Here’s a quick guide explaining how we can do that in few steps.

IIS and Web Application Setup

To enable pretty URL support under IIS, you need to do the following:

  • Ensure that your web server has the URL Rewrite module installed.
  • If you didn’t do that already, move all your MediaWiki installation files within a subfolder of your web application’s root folder, such as /w/.
  • Create (if it doesn’t exist already) a brand-new web.config file and place it within the web application root folder.

If you did everything properly, root folder of your web application should contain the web.config file only, being it the one that will handle the page redirects: all the MediaWiki files, including the LocalSettings.php configuration file, will be in the /w/ subfolder instead.

MediaWiki Configuration

Once done, open the aforementioned LocalSettings.php file and modify it to match the following values:

This will enable pretty URL support for our MediaWiki: however, we still need to properly rewrite these pretty URLs requests, otherwise they will hit a 404 – Page Not Found HTTP error.

Web.Config file

In order to do that we need to properly configure the previously added web.config file to handle pretty URLs. Here’s a working sample:

As we can see, the highlighted rules will rewrite each and every pretty URL request to their corresponding ugly one, so our index.php file will be able to take care of them accordingly and thus return the actual page in a transparent way. Needless to say, nothing of this will work if your IIS is lacking the URL Rewrite Module (see paragraph 1 of this post).

Colons bug in IIS 7.5

If you’re running IIS 7.5 you might also incur in another issue that seems to happen under certain circumstances when an URL contains unescaped colons. The issue is well documented in this StackOverflow post, which also provides a decent workaround if you can’t upgrade to IIS 8.0 or above (which fixes that for good):

Add the following in your MediaWiki‘s root web.config file:

And also add the following JQuery snippet into the MediaWiki:Common.js special page of your MediaWiki installation:

If you never used the MediaWiki:Common.js page, you can read how it works on the official MediaWiki documentation or on this StackOverflow answer. In short words, it’s a quick way to add a JavaScript snippet to every page without having to manually edit the MediaWiki source code or add additional resource files.





About Ryan

IT Project Manager, Web Interface Architect and Lead Developer for many high-traffic web sites & services hosted in Italy and Europe. Since 2010 it's also a lead designer for many App and games for Android, iOS and Windows Phone mobile devices for a number of italian companies.

View all posts by Ryan