By brian, 2 months and 15 days ago

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:
    1. <?php

    at the very top of the file.

    Replace with:

    1. <?php
    2. //*****************************
    3. //    IIS FIX
    4. //
    5. $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL'];
    6. //*****************************
  3. create the following htaccess file with the Helicon Manager:
    1. RewriteEngine On
    2.  
    3. #RewriteBase /
    4.  
    5. RewriteCond %{REQUEST_FILENAME} -f [OR]
    6. RewriteCond %{REQUEST_FILENAME} -d
    7. RewriteRule . - [L]
    8. RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-.*) $2 [L]
    9. RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
    10. 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.