Skip to content

Instantly share code, notes, and snippets.

@markhalliwell
Last active March 11, 2016 11:44
Show Gist options
  • Save markhalliwell/5249012 to your computer and use it in GitHub Desktop.
Save markhalliwell/5249012 to your computer and use it in GitHub Desktop.
Redirect local sand-boxed Drupal file requests to a development server. This helps avoid having to sync (sometimes, very huge) file structures onto your local machine.
### Apache Rewrite
# Request resides in your 'sites/default/files' folder.
RewriteCond %{REQUEST_URI} ^/sites/default/files/(.*)$
# File doesn't exist.
RewriteCond %{REQUEST_FILENAME} !-f
# Directory doesn't exist.
RewriteCond %{REQUEST_FILENAME} !-d
# Redirect request to your development or production server.
RewriteRule ^/sites/default/files/(.*)$ http://dev.example.com/sites/default/files/$1 [L]
### 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