

UPDATE 16.09.2009: I don’t update this script anymore, it might not work on newer versions of Wordpress. An updated, more robust solution can be found at http://www.ikailo.com/94/url-modrewrite-workaround-iis-60/, go there if the solution below causes problems for your site.
I’ve been searching the web a bit for a way to make pretty permalinks work correctly on this site. The site is hosted on IIS so using mod_rewrite won’t work, and it’s on a shared server so the option of installing a mod_rewrite alternative for IIS won’t work either. I could get away with having almost pretty urls, with a index.php in them, like this: http://tech.einaregilsson.com/index.php/2007/07/30/pretty-wordpress-permalinks-on-iis/ but I didn’t like it.
The Using Permalinks section on the Wordpress page has a lot of info on this and it links to one solution that uses custom 404 pages to make this work but unfortunately I don’t think it’s a very good solution at all. What it does is parse the url from the 404 string, then re-implement all the rewrite url matching itself, make its own http request to the correct url, then write the data from that request into the response. It’s a good effort but it’s duplicating functionality already in Wordpress and making a new http request for every page hit which I don’t like. After searching around some more I found another 404 page solution that is very simple and elegant. All you have to do is create a 404 page and put the following 4 lines in it:
<?php
$qs = $_SERVER['QUERY_STRING'];
$pos = strrpos($qs, '://');
$pos = strpos($qs, '/', $pos + 4);
$_SERVER['REQUEST_URI'] = substr($qs, $pos);
$_SERVER['PATH_INFO'] = $_SERVER['REQUEST_URI'];
include('index.php');
?>
All this does is fix the REQUEST_URI and PATH_INFO variables and then include index.php, so Wordpress will do the rest. It’s simple, it doesn’t duplicate functionality already in Wordpress and it doesn’t have the overhead of another http request for every page hit. The installation steps are:
/%year%/%monthnum%/%day%/%postname%/
Welcome to tech.einaregilsson.com
. I’m setting up this site mostly to keep track of my various small programming projects. I have quite a few Mozilla extensions, some Greasemonkey scripts, Wordpress plugins and one or two .NET projects scattered around the web, so I thought it would be good to gather them all in one place. Many of them are still hosted elsewhere but there will at least be a link to all of them here. I haven’t finished putting everything on the projects page yet but it’ll be there soon.
I might also write the occasional blog post, however I have my personal blog (in icelandic) over at einaregilsson.com so this place will only be for tech related stuff. I have a few technical things I´ve been wanting to write about but wouldn’t be of interest to the readers of my personal blog so I´ll post them here when I have the time.





