Apache local fallback images

Inspired by Chris Marslender from 10up’s great post on how to get your local server to use development or live server uploads on NGINX, I knew I needed a solution for my local Apache server.

This is a really simple solution to add to your .htaccess file. The result is that your server will simply use images from the live site whenever it doesn’t find a local version, so you don’t have spend the time and resources downloading them. A big time saver. Also a big headache saver.

Add before your WordPress code:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^wp-content/uploads/(.*)$ http://jupitercow.com/wp-content/uploads/$1 [R=301,L]

Where wp-content/uploads/ is the path to your local uploads directory, and http://jupitercow.com/wp-content/uploads/ is the link to your remote uploads directory.