ISAPI_Rewrite for WordPress permalinks on IIS

14 Jan ISAPI_Rewrite for WordPress permalinks on IIS

We’re setting up a WordPress installation on a Microsoft IIS server that already had Helicon’s ISAPI_Rewrite installed on it.

WordPress is built on PHP and by default expects to use mod_rewrite on Apache, but there are several options that allow “pretty URLs” on IIS as well. ISAPI_Rewrite is one of those options (must be purchased).

We opted for using WordPress’s documented “custom structure” for it’s permalinks and just entered “/%postname%” as the custom structure. This allows a page that would normally look like this:

http://mysite.com/index.php?id=325

And then changes it to a more SEO- and human-friendly URL:

http://mysite.com/about/

Now a lot of what we found online was geared toward WordPress Posts…but we’re using WordPress primarily for the WordPress Pages, not the Posts.

The examples we found on WordPress’s site didn’t achieve what we wanted. And plus, using “/%postname%” alone causes issues for system pages like the Admin area pages. The workaround code for this on the WordPress site didn’t work for us.

So we headed over to Helicon’s site. Their forums had a number of suggestions that we couldn’t get working just right either. But we found one that was REALLY close, the only problem was that a page at the root of the domain wouldn’t load (the homepage)…the sample was for when WordPress is installed as a sub-diretory which we didn’t want. We needed WordPress to be at the root of the site for the homepage.

In the end we added one extra rewrite rule to what we found on Helcion’s forum and bingo! Below is the code that works for us. This is to be entered into ISAPI_Rewrite for the site on the server, and used in conjunction with the permalink custom structure setting of “/%postname%” in WordPress’s admin area.

#################################
# BEGIN Helcion ISAPI_Rewrite rules for WordPress

RewriteEngine on

# Allow homepage
RewriteRule /$ / [L]

# For file-based wordpress content (i.e. theme), admin, etc.
RewriteRule /wp-(.*) /wp-$1 [L]
RewriteRule /js/(.*) /js/$1 [L]
RewriteRule /images/(.*) /images/$1 [L]

# For normal wordpress content, via index.php
RewriteRule /(.*) /index.php\?/$1 [L]

# END Helcion
#################################

Hope that helps someone!

Tags:
,