Archive for May, 2009

Improve Wordpress permalinks in IIS7

Tuesday, May 5th, 2009

Using Wordpress on a Windows Server with IIS7 causes the permalinks to have “index.php” in the url. An example would be “http://www.smartasseses.be/index.php/2009/05/05/improve-wordpress-permalinks-in-iis7″, while this url is a valid link which will be spidered by search engines, it isn’t as esthetical as one would like.

Removing the “index.php” is rather straightforward, once you know how to. First you wan’t to add the following Web.Config to you virtual directory running the Wordpress blog. This will enable a rewriting rule in IIS7, which will rewrite every request that does not point to a physical file to “index.php”. Basicly transforming it to the way it previously worked.

<?xml version="1.0"?>
<configuration>
    <system.webServer>
      <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>
    </system.webServer>
</configuration>

Once we’ve added the config we can change the permalink structure in the admin pages of Wordpress. Choose your structure and remove the “index.php” prefix, be sure to leave a slash at the beginning of the desired structure.

// Change this:
/index.php/%year%/%monthnum%/%day%/%postname%/

// To this for instance:
/%year%/%monthnum%/%day%/%postname%/