Skip to content

Instantly share code, notes, and snippets.

@rahilwazir
Last active October 31, 2018 13:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rahilwazir/cc55d1d3834bb6177de6b2fd00f8eed6 to your computer and use it in GitHub Desktop.
Save rahilwazir/cc55d1d3834bb6177de6b2fd00f8eed6 to your computer and use it in GitHub Desktop.
Map uploads dir to remote server

Nginx

Put this within server { ... } block of your vhost

location ~ "^(.*)/wp-content/uploads/(.*)$" {
    if (!-e $request_filename) {
        return 302 http://yourlivesite.com$request_uri;
    }
}

Apache

Place it under wp-content/uploads/ directory

<IfModule mod_rewrite.c>
  RewriteEngine On

  RewriteBase /wp-content/uploads/
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*) http://yourlivesite.com/wp-content/uploads/$1 [P,L] # use R=302 if P does not work

</IfModule>

NOTE: If the files are not being fetched from remote server, replace P flag with R=302, resulting it into [R=302,L] in your .htaccess file

Source

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