I'm trying to load images from a staging site if they don't exist locally. This is basically useful so I don't have to keep downloading all the images that the client uploads on the staging site. At the moment, what I have is working, but it's an all-or-nothing solution. So, all the images are loading remotely but I'd like htaccess to only load remote images if a local one doesn't exist.
Here's what I have:
RewriteCond %{HTTP_HOST} ^local-site\.dev$
RewriteRule ^.*/uploads/(.*)$ http://remote-site.com/wp-content/uploads/$1 [L,R=301]
Thanks in advance.
Change your rule to this:
Here
RewriteCond %{REQUEST_FILENAME} !-f
will make sure that this redirection happens only when image file doesn't exist locally.