Don't sync Drupal files to local environments. Redirect them Instead.

3266013003 cba186488d o

Don't sync Drupal files to local environments. Redirect them Instead.

This may be a rather short blog post, but it is mainly because this is such a simple solution. Recently my computer barked at me for having having practically no disk space left. Probably like most, I was in the middle of something and promptly ignored it. That is until I attempted to save the file I was working on and instead crashed. I was a bit perplexed as what could be consuming so much space on my respectable 500GB hard-drive. So I quit all my applications and temporarily deleted all my temporary files (to gain a little leverage) and fired off a deep space scan using the amazing open-source app: GrandPerspective.

[[{"type":"media","view_mode":"media_original","fid":"31518","attributes":{"alt":"","class":"media-image","height":"560","typeof":"foaf:Image","width":"720"}}]]

After a few twiddles of the thumb and maybe a yawn or two, I was shocked to see how many files were that of just clients and their websites. After I thought about it, it made sense. Not only do some of these clients have huge websites, but they often contain the raw image files plus all their "image style" variations. This undoubtedly all adds up and needless to say, rm -rf was my friend that day. ;)

I decided to give this some thought and came up with a solution using Apache rewrite rules. This will redirect any local requests to the sites/default/files directory and if they don't exist, it will redirect them to a server that does. No longer do I need to sync a site's entire file structure to my local machine just to ensure an exactly replica.

It's the little things.

If you find this useful or have a similar solution, please feel free to comment below.

Related Posts

Drupal URL Redirect after Node Creation

Chris Sloan
Read more

Requiring Registration to Download Files in Drupal

Randall Knutson
Read more

Drupal Theming - A Basic Primer on Template.php and Template Files

Kristin Brinner
Read more

Local University Website Hacking -- Drupal Security Matters

Kyle Taylor
Read more

Redirect all requests to a canonical domain

Dustin Currie
Read more

Why Google Reviews Matter for Local SEO

Felipa Villegas
Read more