WordPress Permalinks on IIS with ISAPI_Rewrite

I’ve run WordPress here on my CentOS box for nearly 4 years and am quite familiar with the software. Recently, I had a client on a Windows system request a blog be added to their web store. Their webstore is written in ASP and runs on windows. They wanted to stay on the same domain for SEO purposes, (thus site.com/blog/ instead of blog.site.com or a new .com). Without the subdomain or new IP, there’s no way to change DNS for a subdirectory to a different server. This meant I had to get it working on IIS.

Native installations for apache tend not to port well (or perhaps, easily) over to windows/IIS. Thankfully, ISAPI3 from HeliconTech.com supports .htaccess files and makes the job a little easier. WordPress works fine on windows/IIS until you want nice permalinks.

After MUCH searching, testing, and error log analysis, I’ve got a working solution for Windows Server 2003 with ISAPI_Rewrite 3.1.x, running php 5.2.x and mysql 5.0.x community.

  1. index.php should be set up in IIS as a default document (same place you find default.asp, index.htm, etc)
  2. edit wp-settings.php
    Find:

    <?php

    at the very top of the file.

    Replace with:

    <?php
    //*****************************
    //    IIS FIX
    //
    $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL'];
    //*****************************

  3. create the following htaccess file with the Helicon Manager:

    RewriteEngine On

    #RewriteBase /

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule . - [L]
    RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-.*) $2 [L]
    RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
    RewriteRule . /blog/index.php [L]

    • Note: You may need to alter the RewriteBase or the last rule to your specific location. In my particular case, I was installed on domain.com/blog/

From here, you can edit your permalink structure as you normally would. If the default options has index.php/ as part of the rule, you can remove that.

This entry was posted in Programming, Server Administration and tagged , , , . Bookmark the permalink.

6 Responses to WordPress Permalinks on IIS with ISAPI_Rewrite

  1. Always good to learn more about .htaccess – thanks!

  2. Anders says:

    Thanks, works perfect!

  3. Jay Harley says:

    Works like a charm! :) Thanks!

  4. Tin Ceiling Express says:

    I’m still having a little trouble getting this to work. Do you know where I can go to get more WordPress info on how to set up all of the tricks on my website? I’m looking for something a little more basic where it can walk me through more of a copy and paste option…

  5. dab says:

    thankx man, works brilliant!!

  6. Does this work on Windows 2003 Server, IIS 6?

  7. Thanks for the tool but I’m a newbie and still having a difficult time getting it to work. I need to change DNS for a subdirectory to a different server. Any suggestions?

  8. Edwin says:

    I’m still new to WordPress and this helps alot. This will go directly into my saved documents for future reference. Thanks again for the coding.

  9. This was very helpful—especially when this post was originally written. It’s actually a lot easier now. I’m currently using Windows 2008 server, but I’m actually considering switching to Linux. I’m a huge advocate of WordPress, and the latest version of Drupal is pretty good too.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>