X

How to Get Production Files If Not in Local Version

Snippets by IsItWP

Are you looking for a way to get production files if not in local version? While there’s probably a plugin for this, we have created a quick code snippet that you can use to get production files if not in local version in WordPress.

If you have a local “development” version of a WordPress site, and a production version of the same site on a live server, and the 2 should stay in sync, and also use the same database; BUT you don’t want to sync all the files that get added all the time (that just sucks).

THEN, this code can help you with that. What it does is it attempts to load files from production if they’re not in your local version.

Example: Client adds a new blog post with a photo attached to the live server. Since your local site is connected to the same database, the blog post will show up but the image doesn’t (since it’s uploaded to the live server and not your local computer).

You’ll get a 404 because http://local.sitename.com/wp-content/uploads/image.jpg doesn’t exist. But it does exist on http://sitename.com/wp-content/uploads/image.jpg. So, what this code does is that it attempt to load files from production even if they’re not in your local version!

This scenario somewhat implies that you use version control GIT, and we recommend reading this article about keeping WordPress under version control.

Instructions:

All you have to do is add this code to your theme’s .htaccess file or in a site-specific plugin:


# Attempt to load files from production if they're not in our local version
<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule (.*) http://bohmansjostrand.com/wp-content/uploads/$1
</IfModule>

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly add code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: 11 best WordPress quiz plugins and how to secure your WordPress forms with password protection.

Comments   Leave a Reply

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!