Nginx URL rewriting fix for WordPress

Are you using nginx with wordpress, and stumped why your category and post pages aren’t working? Here’s a really simple trick I stumbled upon that fixed my problem instantly.

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

Putting this after my “location ~ \.php$” block fixed the problem, and I was able to load any page I wanted on WordPress. Huzzah!