nginx Rewrite for AtomPub on Wordpress with Clean URLs

For my other blogs, Axis & Allies.org and Beer 47, I've shortened my workflow by pushing the photos directly from Adobe Lightroom to Wordpress using the plugin LR/Blog. However, since I'm using nginx as my webserver, the AtomPub url was not working out of the box but I figured it out and I have the solution in this post.

For it's Wordpress integration, LR/Blog can use either XML-RPC or AtomPub to publish photos. Each have their benefits and drawbacks: XML-RPC doesn't transfer the metadata for the photo, such as the title and caption, and AtomPub does not allow the photos to be updated. Since I only publish my photos one, I would much rather use AtomPub to include the titles and captions.

The default URL for the Wordpress AtomPub integration is /wp-app.php/service but since I did not have a rewrite rule in nginx, I simply received a 404 error, file not found. After some experimentation I added this rewrite rule.

if ($request_uri ~* "^/wp-app.php.*$" ) {
    rewrite ^/wp-app.php/(.+)$ /wp-app.php?q=$1 last;
    break;
}

If you are using clean urls, you will likely have a rewrite block something like this:

if (!-e $request_filename) {
    rewrite ^(.+)$ /index.php?q=$1 last;
    break;
}

Be sure to put your new rewrite rule before your clean url rewrite rule.