Update for Wordpress Permalinks on IIS
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.
October 26th, 2007 at 12:40 pm
THANK YOU SO MUCH! Dude, I have been racking my brain with this ever since I installed WP. I was [—-] this close to switching my hosting plan (which I will one day anyways) to a linux box - but now i have this solution!! THANK YOU!
October 26th, 2007 at 12:49 pm
P.S.
Is this a bot killer?? IE - will I lose traffic due to this? Please email me about this.
October 26th, 2007 at 9:43 pm
I’m glad it helped.
No it’s not a bot killer. It is the exact opposite. It makes your site SEO friendly by removing the ?’s.
October 27th, 2007 at 9:09 am
Thanks again!
November 1st, 2007 at 8:56 am
Hi,
thanks, it works great. I just had to delete the free space at the end, between ? and > .
But now a question. Why the URL is changing into one without www ??? Can I change it somehow?
November 15th, 2007 at 10:29 pm
Hi, do you know if that will work with wordpress mu?
December 5th, 2007 at 5:32 pm
Hi, I’m using a custom 404.php page on an IIS server.
I’m using the wp-404-handler.php and set-up the server as you described but when I enter a bad url I get an error:
Fatal error: Call to undefined function get_header() in C:\Inetpub\wwwroot\blog\wp-content\themes\glossyblue-1-4\index.php on line 1
Any idea what might be causing the error?
December 18th, 2007 at 8:30 pm
My Permalinks Include The “index.php”
But I dislike T-T
January 8th, 2008 at 7:17 am
Nice post!
However, I have a small problem. IIS doesn’t seem to pass $_POST and $_GET variables this way, at least my print_r ($_POST); returns nothing if I put it in 404-handler.php.
It’s a big problem, since I have on my blog…
January 14th, 2008 at 3:08 am
Thankyou so much! I have been looking for something like this for ages and you are the first place that has a working answer!
February 17th, 2008 at 11:07 am
Thanks! I couldn’t get it working at first, but then realised I also needed /wp in the URL as I’ve got WordPress installed in a sub-directory.
April 2nd, 2008 at 10:26 am
Thank you so much for this! It works awesome!
April 12th, 2008 at 5:30 pm
Thanks! This worked great.
One small issue. Now when I type in a wrong url, I just get a blank white page with no code at all, rather than a WordPress page not found error.
It DOES appear to be making it to the index.php page, but then it blows up somewhere I guess. I didn’t have a 404.php page in my theme and thought that might be causing it, but I copied the one from the default theme and it didn’t help.
Has anyone else seen this problem?