A place for my programming projects and the occasional blog about technology related matters.
Pretty Wordpress Permalinks on IIS
Author einar | 30.07.2007 | Category code, meta, wordpress
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'];
$_SERVER['REQUEST_URI'] = substr($qs, strpos($qs, ':80')+3);
$_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:
- Create the file wp-404-handler.php in your base Wordpress folder. (you can also download it here).
- Set your sites 404 page to point to the wp-404-handler.php url. Most control panels at web hosts allow you to do this. If you’ve got the option to select between FILE and URL then choose URL.
- Go to Options -> Permalinks in your Wordpress admin page, and choose an appropriate structure for your links. I chose Custom with this pattern:
/%year%/%monthnum%/%day%/%postname%/ - Enjoy!
First post
Author einar | 26.07.2007 | Category meta
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.
Categories
- ASP.NET (1)
- C# (4)
- code (10)
- extensions (2)
- haloscan (1)
- javascript (2)
- meta (2)
- mozilla (2)
- msn (1)
- plugins (2)
- python (3)
- tips & tricks (3)
- utilities (1)
- Visual Studio (1)
- wordpress (5)
- zenphoto (2)