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.
Ivo says
Scratch my previous cry for help, Einar helped me out with his post. Now the problem is that any other 404 on my whole website (that is not my blog) is a blank page. Anyone have a solution for this?
blog: http://www.seabrookwa.com/blog
website: http://www.seabrookwa.com
THANKS!
Ivo says
I followed your instructions and it worked. However, now the blog’s main page shows me my sidebar while the individual post pages only have the post text and not the sidebar.
Any ideas on why that is?
THanks!
Mujtaba says
hi thanks for the code, it worked like a charm!
i want to know if its possible to write a custom 404 page which can handle bbpress permalinks as well as wordpress permalinks in the same 404 file. iam running the forum at mywebsite/forum
thanks
Sean says
Custom 404’s while preserving the ability to have permalinks are possible using this hack with a small tweak — see http://dotnetyuppie.com/2009/09/21/permalinks-and-mod_rewrite-headaches-in-wordpress-with-iis/
Andy Boyns says
“Be aware though that as this currently stands it does prevent you from using $_POST and $_GET as Hep pointed out above. So if you have a contact form or something similar that requires this then this solution wont work for you.”
Has anyone any idea how to make this work. I need to use qTranslate, and this requires me to use ?Lang=TR
Iris Isac says
Thanks a ton for this solution. I had seraching a lot for it and now I am using it in WordPress thesis theme with IIS. HHowever I have a problem, when I go to individual post the page is refreshing again and again. I am not able to resolve it. Can someone hwlp please?. My Blog is for a tour operator in India @ http://www.irisholidays.com/blog/volunteering-vacations-in-kerala/2010/03/05/