NginX: WordPress + W3 Total Cache Minify Rewrite Rules

by Pranav Rastogi on November 4, 2010

Want to use W3 Total Cache’s Minify on your WordPress blog which runs on NginX? No problemo. I faced the same problem at first but couldn’t find much info digging around, so I decided to take a look at W3 Total Cache’s rewrite rules and took some time to write them for my NginX configuration.

Note: I’m using Memcached in my minify settings.

Here’s a snippet from my NginX configuration:

server {
  listen   80;
  access_log  /var/www/example.com/log/access.log;
 error_log      /var/www/example.com/log/error.log notice;
server_name   example.com;
root /var/www/example.com/public_html;
rewrite ^/wp-content/w3tc/min/([a-f0-9]+)\/(.+)\.(include(\-(footer|body))?(-nb)?)\.[0-9]+\.(css|js)$ /wp-content/w3tc/min/index.php?tt=$1&gg=$2&g=$3&t=$7 last;

...*more NginX config stuff*
}

For the Minify rewrite to work, you must add the following line after in server{} block:

rewrite ^/wp-content/w3tc/min/([a-f0-9]+)\/(.+)\.(include(\-(footer|body))?(-nb)?)\.[0-9]+\.(css|js)$ /wp-content/w3tc/min/index.php?tt=$1&gg=$2&g=$3&t=$7 last;

Make sure that your WordPress root is set to the correct directory otherwise the Minify rewrite will not work.

Previous post:

Next post: