HOWTO: Wordpress pretty URLs with Nginx 0.6 (the proper way)


October 9th, 2009

A lot of guides around the net for Nginx + Wordpress suggest something like this:

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

This is Bad. Try this:

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

What’s the difference? Well, the latter form doesn’t set a GET variable. Why is that better? wp-super-cache, should you choose to use it, refuses to create supercache files when the GET URL has variables in it. If you turn on the debug log, you see errors like these stream past:

Supercache caching disabled. Non empty GET request.
Supercache disabled: GET or feed detected or disabled by config.

You can find a full example of the required Super Cache config here.
 
 
Update:
For nginx >0.6.36 you can use the try_files directive instead:

location /blog { try_files $uri $uri/blog.index.php; }

There’s a full example with this new method in this mailing list post.

Archives

Misc