One of the most annoying things about setting up a dev environment for an existing WordPress site is syncing the content. Pulling down the database is trivial, even a large site will have a relatively small database dump. I often use the WordPress Duplicator plugin. But a site with years of photos and other uploads can have gigabits of files and it’s not really ideal to have to pull those all down from the site.
Today I came across a solution that made me feel stupid for not having thought of it. Iain Poulson posted 5 Ways to Sychronise WordPress Uploads Across Environments, IMHO #4 is the only one you really need to use:
RewriteEngine On
RewriteBase /wp-content/uploads/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) http://yourlivesite.com/wp-content/uploads/$1 [L,P]
So for any file requested within wp-content/uploads/, that does not exist, it will serve the image from http://yourlivesite.com.
The only minor downside with this approach is the lack of offline. If you lose access to an internet connection, you lose access to the live site files, obviously.
Leave a Reply
Only people in my network can comment.