Making ColdFusion/Flash Remoting and WordPress Play Nice on IIS

OK, this post isn’t completely about Flash, Flex, or Mobile, but it is about ColdFusion, so I guess it’s still applicable…  I recently made a few changes my WordPress blog (specifically adding “pretty” permalinks for posts).   In order for this to work properly, you have to add rewrite rules in your web.config so that IIS will be able to map URLs to wordpress/PHP, where it can correctly resolve the URL to the actual post.   (You can read more about WP permalinks here.)

Once you setup the rewrite rules, all is well and good, right?  Well, almost… This is an IIS server, running ColfFusion and PHP.   While the wordpress blog was working great, I realized that all of my AMF remoting on the server stopped working.  It turns out that the rewrite rules were affecting all pages that don’t physically exist.  This includes the “/Flex2Gateway/” endpoint used by ColdFusion to resolve all AMF requests.  Note: the “Flex2Gateway” url path doesn’t point to a physical folder or file; it is a virtual mapping.

In order for WordPress and ColdFusion to play nicely together on the same server, you will need to setup your rewrite rules to map all URLs that don’t contain the string “flex2gateway”.   It’s not that complicated really, but took a little while to track down what exactly was happening.  I used the ECMAScript pattern syntax for a regular expression that will match all strings that don’t include “flex2gateway”, and here’s the final solution:

<rule name="wordpress" patternSyntax="ECMAScript">
<match url="^((?!flex2gateway).)*$" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<action type="Rewrite" url="index.php" />