How to set up Pretty Permalinks on IIS7

WordPress was originally meant for Linux servers running Apache.  Apache has a nice module called mod-rewrite, which basically allows the usage of pretty permalinks.  Pretty permalinks are URLs that are easy to understand by a user, and really help search engines index your pages… hence the main reason webmasters want to implement these in the first place. 

Windows server have been out of luck when it comes to WordPress.  The didn’t have a good URL-rewriter or a good caching system… and installing PHP on IIS isn’t a walk in the park either. 

IIS7 changes all of that.  I’ve blogged about these features in other posts, so I won’t rant about them here.  Here’s how you enable pretty permalinks in WordPress on IIS7.

In WordPress, go to Settings, and then Permalink.

Click Custom and enter your permalink format.  I use

/%year%/%monthnum%/%day%/%postname%/

It’s pretty  much the same as the default date, but without index.php at the front.

Click Update Permalink Structure

Now you have to edit the web.config file at the root of the WordPress site.  Insert the following code between the system.webServer elements…


<rewrite>
    <rules>
        <rule name=”Main Rule” stopProcessing=”true”>
            <match url=”.*” />
            <conditions logicalGrouping=”MatchAll”>
                <add input=”{REQUEST_FILENAME}” matchType=”IsFile” negate=”true” />
                <add input=”{REQUEST_FILENAME}” matchType=”IsDirectory” negate=”true” />
            </conditions>
            <action type=”Rewrite” url=”index.php” />
        </rule>
    </rules>
</rewrite>

Save it, and POOF!  Your URLs should magically work without the ugly index.php parameter.  Now let Google and the other search engines go crazy on your site!

Alan is a web architect, stand-up comedian, and your friendly neighborhood Grammar Nazi. You can stalk him on the Interwebs via Google+, Facebook and follow his ass on Twitter @ocmodshop.