IIS + PHP 404 hack for Wordpress
Wednesday, July 30th, 2008Finally decided to fix and re-release this little code snippet.
You can have fancy urls for wordpress in IIS without any need for a url rewriter. Then again, this is really the only way I know to do fancy urls in IIS..
Anyway, simply take this code:
<?php
//404 hack
//by the mickelphin
//Get the end of the url
$urlstub = substr($_SERVER['REQUEST_URI'], strrpos($_SERVER['REQUEST_URI'],”:80/”)+4);
$_SERVER['REQUEST_URI'] = $urlstub;
$_SERVER['PATH_INFO'] = $urlstub;
//Attempts to repair corrupted get data, iis bug
foreach ($_GET as $id => $data) {
$_GET[substr($id, strpos($id,"?")===false?0:strpos($id,"?")+1)] = $data;
}
require “index.php”;
?>
And insert it in a file called 404.php in your blog directory.
Then open up IIS’s config and move to your blog directory. Open up properties for that, and go to the Custom Errors tab. Click on the first 404 entry [and only the first], press edit, change it to url, and put in ‘ /[your blog directory, if any]/404.php ‘.
Ok on out. In wordpress, change your permalink style to exclude index.php. ie simply: ‘ /%year%/%postname%/ ‘ or whatever.
And have fun. I’m using it now.
If you have any issues, feel free to leave a comment.