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.

Tags: , , ,

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. 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!!

Leave a Reply