Skip to content

Instantly share code, notes, and snippets.

@stevegrunwell
Created June 12, 2012 14:49
Show Gist options
  • Save stevegrunwell/2917979 to your computer and use it in GitHub Desktop.
Save stevegrunwell/2917979 to your computer and use it in GitHub Desktop.
Load production WordPress uploads in a local version of the site by putting this in a new Htaccess file in /wp-content/uploads/
# Attempt to load files from production if they're not in our local version (replace {SITE URL} with your production server)
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) http://{SITE URL}/wp-content/uploads/$1
</IfModule>
@Loosie94
Copy link

Any idea how to use this with NGINX?

@stevegrunwell
Copy link
Author

@Loosie94 try something like this:

server {
    server_name example.test;
    set $production example.com;

    # Rewrite requests to the production server.
    location @production_uploads {
        rewrite "^(.*)/wp-content/uploads/(.*)$" "https://$production/wp-content/uploads/$2";
        break;
    }

    # If uploads can't be found locally, try checking production.
    location ~ "^/wp-content/uploads/(.*)$" {
        try_files $uri @production_uploads;
    }
}

@Loosie94
Copy link

Hi Steve, thanks! Funny thing; I found the same solution that you provide. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment