Tag Archive for 'htaccess'

mod_rewrite Google’s proxy cache

A few days ago I wrote about how to configure Wordpress to use Google’s cache proxy servers to serve images. After writing that entry I kept thinking to myself that there had to be a better/easier way to accomplish this other than changing Wordpress settings. Well I finally figured it out and got it working on my other blog DavidChiu.net. It involves using mod_rewrite and symbolic links. First you need to create a symbolic link to the Wordpress /uploads/ folder. For example:

ln -s wp-content/uploads/ images/cache

Then you just need to modify your .htaccess file:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^.*wp-content/uploads(.*) http://gmodules.com/ig/proxy?url=http://davidchiu.net/images/cache$1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

And voila! All images will now be served by Google’s proxy cache!