Developer magic: develop locally, but retrieve sites/default/files from production server

Lullabot nailed it: If you work on large Drupal sites, you probably run into the problem of the enormous "files" directory. Keeping your development server (or personal computer) in sync with production is a big pain, but without those uploads and file attachments it's easy to miss important design problems with site content.

They provide a fix, but one thing we would like to do is serve the local file if it exists, only then access the remote server. This is the set of rewrite rules we recommend you put in your vhost definition (don't touch your Drupal .htaccess):

<VirtualHost *:80>
  ServerName www.example.com
  DocumentRoot /home/me/src/www.example.com

  <IfModule mod_rewrite.c>
    RewriteEngine on
    # Force image styles that have local files that exist to be generated.
    RewriteCond %{REQUEST_URI} ^/sites/([^\/]*)/files/styles/[^\/]*/public/((.*))$
    RewriteCond %{DOCUMENT_ROOT}/sites/%1/files/%2 -f
    RewriteRule ^(.*)$ $1 [qsappend,last]
    # Otherwise, send anything else that's in the files directory to the
    # production server, if it does not exist.
    RewriteCond %{REQUEST_URI} ^/sites/([^\/]*)/files/(.*)$
    RewriteCond %{REQUEST_URI} !^/sites/[^\/]*/files/css/.*$
    RewriteCond %{REQUEST_URI} !^/sites/[^\/]*/files/js/.*$
    RewriteCond %{DOCUMENT_ROOT}/sites/%1/files/%2 !-f
    RewriteCond %{DOCUMENT_ROOT}/sites/%1/files/%2 !-d
    RewriteRule ^(.*)$ http://www.ljhooker.co.nz$1 [qsappend,last]
  </IfModule>

</VirtualHost>