MediaWiki and IIS redirect loop issue: how to fix it

How to enable the WikiEditor in your own MediaWiki

If you've stumbled upon this post, it means that you ran into a common issue happening right after installing/upgrading to MediaWiki build 1.26.2 (and above) under a Windows/IIS environment. The problem arises everytime you try to request a URL containing special characters, such as colon or ampersand: the browser will try to load the page for 20-30 seconds, then it will timeout with a redirect loop error like the following:

This Webpage has a redirect loop

Error 310


... and so on. Since all MediaWiki's special pages contains at least a colon, this will most likely prevent you from running any of them.

The Problem

It's worth noticing that this issue is not related to the dreadful IIS 7.5 colon bug, which prevents older versions of IIS to properly handle URLs with colons (we mentioned it here, also providing a JavaScript-based fix). As a matter of fact, we're dealing with a completely different pair of shoes here: a regression bug most likely caused by this patch to the MediaWiki source code, shipped in 1.26.2 and above releases up to 1.27.0, where the value of the requested url is compared to what appears to be believed to be the canonical url:

The problem with this code is that it will always fail under IIS due to the fact that the request URL is determined using the $_SERVER['REQUEST_URI']  environment variable, which happens to behave differently between Apache and IIS when it contains URL encoded characters.

The Solution

Unfortunately, this issue can't be addressed at configuration level by changing the   $wgUsePathInfo  or   $wgArticlePath values, as it has nothing to do with them: the only viable workaround I found for now is to apply the following change to the /includes/MediaWiki.php code from this (lines 344-348):

to this:

This might be a bit extreme, since it means changing the core MediaWiki source code, but it will fix the issue for the time being. Let's hope that the upcoming builds of MediaWiki will have it fixed accordingly.



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. Microsoft MVP for Development Technologies since 2018.

View all posts by Ryan

6 Comments on “MediaWiki and IIS redirect loop issue: how to fix it”

  1. Pingback: MySQL Lock Wait Timeout Exceeded Error in InnoDB Tables - How to fix it
  2. Pingback: MySQL Lock Wait Timeout Exceeded Error in InnoDB Tables - Soluzione
  3. Hi,
    Was this fixed in a later version of MediaWiki than 1.27? Can we just upgrade to fix now? Thx

Leave a Reply

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

The reCAPTCHA verification period has expired. Please reload the page.

This site uses Akismet to reduce spam. Learn how your comment data is processed.