URL Mod-Rewrite Workaround for IIS 6.0 and WordPress
I found that the existing solution for using pretty permalinks with WordPress and IIS is good and lightweight, but I needed something a little more robust that fixed as many differences as possible between Apache and IIS.
This code uses the same idea as the above, but fixes more values in _SERVER and resolves a problem with _GET. It will also work with later versions (2.8+) of WordPress.
<?php
// This is the default file for the site. Usually index.php
$default = 'index.php';
// The name of this file.
// Set this value for the URL in Custom Error Properties of your website in IIS.
// Goto: IIS Manager > Websites > [Site Name] > Properties > Custom Errors >
// 404 & 404;2 & 404;3 > URL (Requires a '/' prefix in IIS).
$thisfile = '404-handler.php';
$_SERVER['ORIG_PATH_TRANSLATED'] = str_replace($thisfile, $default, $_SERVER['ORIG_PATH_TRANSLATED']);
$_SERVER['SCRIPT_FILENAME'] = str_replace($thisfile, $default, $_SERVER['SCRIPT_FILENAME']);
$_SERVER['ORIG_PATH_INFO'] = str_replace($thisfile, $default, $_SERVER['ORIG_PATH_INFO']);
$_SERVER['SCRIPT_NAME'] = str_replace($thisfile, $default, $_SERVER['SCRIPT_NAME']);
$_SERVER['PHP_SELF'] = str_replace($thisfile, $default, $_SERVER['PHP_SELF']);
$_SERVER['PATH_INFO'] = false;
$qs =& $_SERVER['QUERY_STRING'];
$ru =& $_SERVER['REQUEST_URI'];
$pos = strrpos($qs, '://');
$pos = strpos($qs, '/', $pos + 4);
$_SERVER['URL'] = $ru = substr($qs, $pos);
$qs = trim(stristr($ru, '?'), '?');
// Required for WordPress 2.8+
$_SERVER['HTTP_X_ORIGINAL_URL'] = $ru;
// Fix GET vars
foreach ( $_GET as $var => $val ) {
if ( substr($var, 0, 3) == '404') {
if ( strstr($var, '?') ) {
$newvar = substr($var, strpos($var, '?') + 1);
$_GET[$newvar] = $val;
}
unset($_GET[$var]);
}
break;
}
include($default);
?>

You are an absolute genius. This seems to be the only thing that worked for me.
However, the only problem I’m having is that the Flash application I have on my homepage stops working. Why do you think it does this, and how do I fix it?
Thanks for this solution! Is there a way for actual 404s to redirect to a page using the 404.php template in my theme directory? Currently invalid URLs that would normally return a 404 show up blank.
You are a lifesaver, I used this for a client that had Windows Hosting and insisted on a wordpress website design. The permalink structure for it was horrible and I know would ruin his search engine optimization strategy of having nice links. Thanks again for this great tutorial!
it is very helpfull!thanks
very helpful and useful with me, thanks for tip !
Dan
This worked a treat. I had no idea that WordPress could work on a Windows machine.
Won’t this cause all pages pages deeper than the homepage to return a 404 status?
This would be horrible from an SEO perspective!
Please advise.
Awesome dude!!!!