There is extensive documentation on Mediawiki on how to shorten the urls from www.yoursite.com/index.php?title=testpage to www.yoursite.com/testpage. After a few hours of research I was able to do just that on my Windows Server 2003 and IIS. It is probably wise to follow the URL pattern of wikipedia exactly so that in future software updates of Mediawiki your site will not break your site accidentally. The more customization you do to your site the more likely is that the development team on Mediawiki will not be testing your specific settings and will not be taking your modifications in mind as they write new code. So it will be safer to mimic wikipedia url pattern: www.yoursite.com/wiki/articlename

I have put this text on MSWiki so that it can evolve: http://mswiki.com/wiki/Short_URLs_for_better_search_engine_ranking

Step by step guide

  1. URL Rewite
    • Install URL rewite for IIS
    • Download the zip file and unpack it somewhere on your server outside of wwwroot
    • Give Network Service account write privileges to above directory.
    • Configure the ISAPI ini file like below. Debug 1 will cause debug output to be written which will help you troubleshoot problems. Reload 5 means that the ini file will be reloaded at every 5 url redirection. This saves you from resrtting IIS every time you change this file.

Debug 1
Reload 5
#Browse LOT
RewriteRule ^/wiki/(.*) /index.php?title=$1

  • On the command prompt type iisreset +<enter>. Your re-director should be working now. Test it by navigating to www.yoursite/wiki/Main_Page.

 

  1. Mediawiki settings
    • Modify MediaWiki localsettings.php to look like below. This will cause internal links on the page to also be shortened

$wgScriptPath     = "";
$wgScript           = "$wgScriptPath/index.php";
$wgRedirectScript   = "$wgScriptPath/redirect.php";
$wgArticlePath      = "/wiki/$1"

  • 'Security Step' If everything is working now then revoke the write permission from Network Service where you saved your ISAPI filter. Then change the ISAPI ini to look like this

Debug 0
Reload 5000
#Browse LOT
RewriteRule ^/wiki/(.*) /index.php?title=$1

  • Some pages on your site will be cached by PHP or IIS and will still have the old style URLs. But eventually, with time or with editing of pages, the files in cache will be replaced.
  • The old style URL will be present for non existing pages. I think this is a bug in MediaWiki software. Even wikipedia has this problem.