Rewrite local image path to remote path

When a client already have a Website and they needed to do some improvements to the existing site, it is important to get the same copy (as close as possible) from their production and set it up local. But how about files?. Can we download all their files? how big would those be?. So it might be a good idea to reference remote images from local. To do that you need to add following rewrite rule to the vhost.

The following is for Drupal 7 installation and replace the REMOTE_URL with your production URL.

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 [QSA,L]
# Otherwise, send anything else that's in the files directory to the
# production server.
RewriteCond %{REQUEST_URI} ^/sites/[^\/]*/files/.*$
RewriteCond %{REQUEST_URI} !^/sites/[^\/]*/files/css/.*$
RewriteCond %{REQUEST_URI} !^/sites/[^\/]*/files/js/.*$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ REMOTE_URL/$1 [QSA,L]