<p>I spent quite a while scouring the web looking for a working solution having had little success myself. I recently stumbled on this working re-write rule to load assets from a remote server if they are not found locally. </p>

<p>I've placed the following code inside of my vhost in MAMP locally, so as not to pollute my production code.</p>

<pre><code>&lt;VirtualHost *:80&gt;

 ... usual serve config ...

  # Look for non-existent assets on live server
  &lt;IfModule mod_rewrite.c&gt;
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f [NC]
    RewriteRule ^(.*\.(png|jpe?g|gif|ico)) http://production.com/$1 [NC,P,L]
  &lt;/IfModule&gt;

&lt;/VirtualHost&gt;
</code></pre>

<p>This snippet was found in <a href="http://rzen.net/serve-missing-media-production-apache-nginx/" rel="nofollow">this blogpost</a> by  Brian Richards. Thanks Brian!</p>

CC BY-SA 3.0
2015-10-02T18:19:21.010Z
2015-10-02T18:19:21.010Z
lowe_22
<p>You could set up your assets through Amazon S3 or another remote service then that wouldn't be a problem.</p>

<p>Alternatively you will need to download all the assets locally if you have relative paths <code>/uploads/images/banners/banner1.jpg</code>.</p>

<p>Though maybe another option is to set the path to include the domain then you can probably get the files from the server (so in your markup you would see the image would be linking to <code>http://www.yousite.com/uploads/images/banners/banner1.jpg</code></p>

CC BY-SA 3.0
2015-09-21T21:04:47.777Z
Amazon etc. would be an obvious solution, but not in the scope of this project. Is there not some way to use .htaccess to look in a remote location if the file doesn't exist? I've tried a few variants, but can't find a working solution so far!
lowe_22
CC BY-SA 3.0
2015-09-22T07:32:46.617Z
I suppose you could try search for ".jpg" etc with a condition, then with a 301 rewrite rule: `www.yoursite.com/$1` though I'm not sure how reliable that would be, not tried it. It should work in theory... If you can't use S3 for what ever reason, OR download the assets, you can change the links to your image sources to a remote location... again I haven't tried it, but you could give that ago...

Another option is to always prefix where you load in images within your template use the {{ siteUrl }} craft variable (or create your own custom var if that makes the site unusable locally).
joep
CC BY-SA 3.0
2015-09-21T10:29:15.557Z
2015-09-21T10:29:15.557Z
joep
<p>I'd like to sync the database of a live site to my local site for development, but don't want to download all the images and files. Is there an .htaccess that could look for the files locally, and on 404 look to the live site? What are the implications for image transforms etc?</p>

<p>There seem to be some solutions available for WordPress and Drupal, but has anyone had any experience with this with Craft?</p>

<p>Thanks</p>

<image><image-transforms><htaccess>
How can I use images from my live Craft Site when developing locally
# How can I use images from my live Craft Site when developing locally

(Asked by: username_0 on 2015-09-21)

I'd like to sync the database of a live site to my local site for development, but don't want to download all the images and files. Is there an .htaccess that could look for the files locally, and on 404 look to the live site? What are the implications for image transforms etc?

There seem to be some solutions available for WordPress and Drupal, but has anyone had any experience with this with Craft?

Thanks

**Tags:** image, image-transforms, htaccess


---

## 2 answers

### Answer by username_0 on 2015-10-02. Score: 1 | Accepted answer

I spent quite a while scouring the web looking for a working solution having had little success myself. I recently stumbled on this working re-write rule to load assets from a remote server if they are not found locally. 
I've placed the following code inside of my vhost in MAMP locally, so as not to pollute my production code.


 ... usual serve config ...

  # Look for non-existent assets on live server
  
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f [NC]
    RewriteRule ^(.*\.(png|jpe?g|gif|ico)) http://production.com/$1 [NC,P,L]
  



This snippet was found in this blogpost by  Brian Richards. Thanks Brian!


---

### Answer by username_1 on 2015-09-21. Score: 3

You could set up your assets through Amazon S3 or another remote service then that wouldn't be a problem.

Alternatively you will need to download all the assets locally if you have relative paths `/uploads/images/banners/banner1.jpg`.

Though maybe another option is to set the path to include the domain then you can probably get the files from the server (so in your markup you would see the image would be linking to `http://www.yousite.com/uploads/images/banners/banner1.jpg`

> **Comments:**
> **username_0**: Amazon etc. would be an obvious solution, but not in the scope of this project. Is there not some way to use .htaccess to look in a remote location if the file doesn't exist? I've tried a few variants, but can't find a working solution so far!  
> **username_1**: I suppose you could try search for ".jpg" etc with a condition, then with a 301 rewrite rule: `www.yoursite.com/$1` though I'm not sure how reliable that would be, not tried it. It should work in theory... If you can't use S3 for what ever reason, OR download the assets, you can change the links to your image sources to a remote location... again I haven't tried it, but you could give that ago...  Another option is to always prefix where you load in images within your template use the {{ siteUrl }} craft variable (or create your own custom var if that makes the site unusable locally).  

---

