Skip to content

Instantly share code, notes, and snippets.

@gormus
Created October 12, 2016 16:47
Show Gist options
  • Select an option

  • Save gormus/d34ade16222805e4bd62a791515e8e8a to your computer and use it in GitHub Desktop.

Select an option

Save gormus/d34ade16222805e4bd62a791515e8e8a to your computer and use it in GitHub Desktop.
Redirects your local environment's Drupal install /sites/*/files/* requests to a server that actually has them. This helps avoid having to sync (sometimes, very large) file structures onto your local machine and taking up valuable hard-drive space. Source: http://dropbucket.org/node/337
### Apache Rewrite
<IfModule mod_rewrite.c>
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 ^(.*)$ http://dev.example.com/$1 [QSA,L]
</IfModule>
### nginx Rewrite
## Try local files first, otherwise redirect to a development server.
location ^~ /sites/default/files {
try_files $uri @dev_redirect;
}
## Development Server Redirect
location @dev_redirect {
rewrite ^ http://dev.example.com$request_uri? permanent;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment