Monday, May 2, 2011

Nginx's Rewrite Rules for WordPress MS In a Subdirectory

Nginx's rewrite rules have been giving me a headache lately. Okay, cool so it doesn't support .htaccess files; that's fine. WordPress' Codex Nginx Page gives me some great information on how to do the rewrites.


Ah but I'm running WordPress in a subdirectory! My site URI for WordPress is something like, http://mydomain.com/subdir/. Okay? Yea should be fine as long as you rewrite the rewrite rules a little bit like so:

if (!-e $request_filename) {
rewrite ^/subdir/[_0-9a-zA-Z-]+(/wp-.*) /subdir$1 last;
rewrite ^/subdir/[_0-9a-zA-Z-]+.*(/wp-admin/.*\.php)$ /subdir$1 last;
rewrite ^/subdir/[_0-9a-zA-Z-]+(/.*\.php)$ /subdir$1 last;
}


That wasn't so bad right? Yea, it confused the heck out of me though at first! So hopefully the next person won't have the same headaches! Cheers!