There has been quite a bit of comments going back and forth on the code that I wrote to enable permalinks for Wordpress on IIS since I put it up on the site. Just recently, Einar Egilsson posted an extremely helpful bit a code in the comments. It’s a much better and cleaner way of accomplishing the same thing.

I was always aware that my solution was a little odd in that it used ASP. WordPress is written in PHP and to use ASP requires odd work-arounds. Einar gave us a great simple solution that uses PHP. It too requires 404 redirects, though.

It’s requirements are:

  • IIS for Windows
  • WordPress
  • Ability to change your 404 error page with your web host.

To install, copy and paste this text into a file named wp-404-handler.php:


<?php
$qs = $_SERVER['QUERY_STRING'];
$_SERVER['REQUEST_URI'] = substr($qs, strpos($qs, ':80')+3);
$_SERVER['PATH_INFO'] = $_SERVER['REQUEST_URI'];
include('index.php');
? >

Next set the 404 error page to /wp-404-handler.php. If it gives you a choice between file and url, choose url.

Lastly, make sure you enable permalinks in the Wordpress control panel under Options > Permalinks.

That should do it.

Thanks to Einar for posting this in the comments and thanks to CaptainN who first wrote about in the Wordpress support forums.