Scenerio: You’re about to make updates to an existing website – you’ve copied all the files and the database to your local machine – except for the media files (in the case of WordPress, anything under /wp-content/uploads. Everything is set up and ready to go.

Good thing you didn’t need to wait hours to download all 4gb of that media uploads folder – because you just popped this code snipped into your .htaccess file (above the WordPress rewrite rules, of course! Nobody ever tells you that part, but I am telling you now. Your welcome.)

This handy snipped will do the following for you:

  1. Only rewrite URL’s if the hostname matches your dev URL
  2. Check that the request is asking for stuff within the media uploads folder
  3. Check your local machine first for existing media (in case you uploaded some as part of your dev changes)
  4. Then rewrite the URL to the live one where needed

A couple of advantages of doing this are:

  1. Takes up less disk space locally (not that you were running out, were you?)
  2. Save yourself a ton of time transferring media files – especially for those video websites or photography websites you are working on
  3. If any images change on the live server, you see the updates immediately

Leave a Reply

Your email address will not be published. Required fields are marked *