Development and staging servers may have less disk space allocated to them than a production server. When you are copying files from your production server back to staging or development, you can quickly fill up your disk space. If this is an issue, it's possible to use the files on the production server for your staging site without copying them. Two of the easier methods you can use are: the Stage File Proxy module or an .htaccess
redirect.
Using the Stage File Proxy module enables a development server to maintain a clean files directory and use files from an alternate source by directly referencing that alternate source. An additional option within the module allows the file system on the development server to be seeded with files from the production server.
.htaccess
rewrites¶If you prefer a lower impact solution and are willing to work in the .htaccess
file, you can use rewrite rules to intercept calls to the file system on development or stage that would otherwise result in an HTTP 404 error.
This procedure assumes that you are placing your files in the sites/default/files
directory, that the request is going to sites/default/files
, and that the system this code is on is non-production.
This enables a user on a non-production site to view any image that has been either uploaded or generated on the production server. Be aware that if the file exists on the non-production server, this redirect may not work properly.
.htaccess
file and look for the following lines:
# Pass all requests not referring directly to files in the file system to
# index.php. Clean URLs are handled in drupal_environment_initialize().
# If the request is to the files directory.
RewriteCond %{REQUEST_URI} ^/sites/default/files/(.*)$
# and the environment is not production
RewriteCond %{ENV:AH_SITE_ENVIRONMENT} !^prod$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Redirect the request to the production server.
RewriteRule ^sites/default/files/(.*)$ http://example.com/sites/default/files/$1 [L]
# SetEnvIf must be used for a variable to be available in
# a RewriteCond in mod_rewrite. SetEnv is not sufficient.
#
# If the request is to the files directory.
RewriteCond %{REQUEST_URI} ^/sites/default/files/(.*)$
# and the environment is not production
RewriteCond %{HTTP_HOST} !^(www.)?example.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Redirect the request to the production server.
RewriteRule ^sites/default/files/(.*)$ http://example.com/sites/default/files/$1 [L]
If this content did not answer your questions, try searching or contacting our support team for further assistance.
Wed Oct 22 2025 08:59:29 GMT+0000 (Coordinated Universal Time)