Getting WP-Super-Cache to work with WordPress on Nginx

I was setting up WP-Super-Cache yesterday when I ran into this gotcha, I’ve done this before so I should have known better, I’m blogging it now so that I don’t forget and anyone else with this issue can be saved some hassle.

Essentially WP-Super-Cache was only half on, it could generate wp-cache files but was not creating static cache files.  The reason for this was that the querystring always contained at least one value even though it wasn’t in my URLs. That drove me crazy until I remembered this morning that the recommended Nginx setup was the problem the last time. The reason for this is the following part of the Nginx config that rewrites any non existing file requests to WordPress’ index.php


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

This will cause WP-Super-Cache to never generate any static cache files since one of its conditions for doing so is that the querystring is empty.
If your Nginx config has this, try changing removing the ?q=$1 as below:


if (!-e $request_filename) {
rewrite ^(.+)$ /index.php last;
}