1

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

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

|improve this answer|||||
  • 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 Sep 21 '15 at 21:04
  • 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 Sep 22 '15 at 7:32
1

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.

<VirtualHost *:80>

 ... usual serve config ...

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

</VirtualHost>

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

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.