WordPress: Load missing uploads

Hi @all,

This is a reminder post and also an extract from this other post http://rzen.net/serve-missing-media-production-apache-nginx/

To avoid copying files from live server across different environments, the best approach is to load the assets from live if they don’t exist in your local or staging server. That will save you a lot of time and it’ll maintain your environments more in sync.

To do it in Apache add the following code to the virtual host declaration:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f [NC]
    RewriteRule ^(.*\.(js|css|png|jpe?g|gif|ico)) http://example.com/$1 [NC,P,L]

Instead, to do it on Nginx, use the following code:

# Directives to send expires headers and turn off 404 error logging.
location ~* \.(js|css|png|jpe?g|gif|ico)$ {
	expires 24h;
	log_not_found off;
	try_files $uri $uri/ @production;

location @production {
	proxy_pass http://crazytraction.com/$uri;

This will help me and it’ll help others I guess, so enjoy!