Recent posts
htaccess Redirect Rule - Psuedo Sync Drupal Files between Development and Production
Create a redirect rule on your local Drupal development server that points to the production server
The files directory of a Drupal install can grow pretty dang big on production sites. Who wants to wait for 2gigs of data to download from production to development! If you're a designer and theming's your game, having all those pretty images in place, is a must. It helps to have production files available without having to download the entire Drupal files directory onto our local development machine.
Redirect all local requests for images to an absolute production url using a redirect rule in an .htaccess file.
RewriteEngine on
Redirect / http://example.com/files/filepath/
Create an .htaccess file in your local /sites/example.com/files directory with the above code and all requests to this directory will be redirected to appropriate folder on the production site.
Turn off css and js aggregation under performance options in your local development site and your development site will load all images from the production url.
Make sure you have your "AllowOveride" rule set to "all" for your Drupal installation. This is set in the apache virtualhost file.
<Directory /home/www/htdocs/drupalcore/*>
AllowOverride All
</Directory>
The only caveat of this way is that any changes to your local files directory will not have any effect on your development front end. Let's say you uploaded an image locally and inserted that image into a page, although Drupal will load the image to the files directory on your local machine, the image won't appear on your page because all requests to the files directory is being redirected to the production server, where the image file does not exist.
Ok, I thought of one more caveat. Image paths have to be absolute urls for this to work. img src="file/imagename.jpg" won't work with the above redirect rule. But img src="http://sitename.com/files/imagename.jpg" will work.
I'm sure some clever conditional rewrite rules with regular expressions would be able to solve both these caveats, but blimey...have you seen regex syntax! I've still got to wrap my head around that one. Maybe Mariano will step in and lend a hand with this.

Conversation
Your enthusiasm for your work reveals itself in every word you write.
Post new comment