Skip to content

Instantly share code, notes, and snippets.

@bryanhirsch
Created April 11, 2015 16:39
Show Gist options
  • Save bryanhirsch/aeed6e26fc792903d38d to your computer and use it in GitHub Desktop.
Save bryanhirsch/aeed6e26fc792903d38d to your computer and use it in GitHub Desktop.
Serve files from prod if not found locally
# Serve files from prod if not available locally per:
# https://docs.acquia.com/articles/serving-files-production-development-environments
#
# If the request is to the files directory
RewriteCond %{REQUEST_URI} ^/sites/default/files/(.*)$
# If we are not on prod
RewriteCond %{ENV:AH_SITE_ENVIRONMENT} !^prod
# If we are not on stage
RewriteCond %{ENV:AH_SITE_ENVIRONMENT} !^test
# If the file or directory is not found
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Then redirect the request to the production server
RewriteRule ^sites/default/files/(.*)$ http://example.com/sites/default/files/$1 [L]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment