A client who hosts their own website recently launched a new version of their site, which had been developed in WordPress instead of the static html site they had before. However, they used their web space to host multiple applications in subdirectories on the domain. This was going to cause problems with WordPress and it’s rewrite rules, since the permalinks may have conflicted with the names of the physical directories where the other applications lived.

For most people’s WordPress installations running on a *nix platform, you would need to go into the `.htaccess` file and insert this RewriteRule above all other rules.

RewriteRule ^(images|intranet)($|/) - [L]

However, this client was hosting their site using Windows so we needed to figure out a way to make the same change under IIS, using the `web.config` file instead. After some digging and testing, we found it only takes a single additional line to add exclusions to the rewrite rules. Here is the full `web.config` file after modification.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="wordpress" patternSyntax="Wildcard">
          <match url="*" />
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
            <add input="{REQUEST_URI}" pattern="^/(images|intranet)" negate="true"/>
          </conditions>
          <action type="Rewrite" url="index.php"/>
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

With that one `{REQUEST_URI}` line, you can pipe-delimit all of the top-level directory names that you wish to exclude from the rewrite rules with IIS.

Hopefully this post helps someone else with the same problem!