Remove Wordpress Index.php on Windows Servers
When hosting a WordPress install on a Windows server, some users encounter a problem using the permalinks feature.
The problem is that some Windows hosts insert index.php into the url, so id you had permalinks set to show the post name (/%postname%/) your links end up looking like:
http://www.yourblog/index.php/your-post-name
Now my preference would be for the index.php to NOT be there, as it adds another level to the URL, disrupts readability, and, IMO, diminishes the SEO impact of a well chosen, keyword-rich post name. The other problem I encountered, at least with this specific blog/theme, was that the search feature didn’t work either, and it seemed to be realted to the unavoidable need to put index.php into the URL.
Alas, fixing this isn’t as easy as you might think. I found several suggested solutions using web.config (for a host with .Net enabled) and some for using ISAPI rewrite, which many hosts already have installed. Unfortunately, there didn’t work for me.
What I ended up using was a custom 404 error handler written in PHP that does the redirect. I implemented this solution on my lowering cholesterol blog and it worked fine, including the search.
Do the following steps to implement:
Get the php code for the Windows index.php WordPress fix and create a file called 404-handler.php in your main WordPress folder. You can change the name as long as you also change the $thisfile variable in the php code. Once you create the file, upload it to the root directory of your blog.
Using whatver hosting control panel your host provides, change the 404 Error Behavior to use a custom page and set the location of the that page to the file you created above, entering the relative path to the file (this means you’ll probably need a / in front of it).
Login to your WordPress site as an admin and update Settings–>Permalinks to the custom value you want:
/%year%/%monthnum%/%day%/%postname%/ or /%category%/%postname%/ or whatever.
That’s it! Now you’ve got pretty permalinks on a Windows server!
And for those of you who scoff and simply say “Just get a Linux host” I want the availability to do PHP, .Net and ASP development in one place.