Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a stage and dev server. I periodically pull the database from stage to local, but not the images due to lack of write permissions on stage. I know that you can write rewrite conditions for pulling all images from a remote location, but is there any way to tell Apache to first look on local, and if not found, then grab the images from remote?

share|improve this question
up vote 3 down vote accepted

You can use the -f flag in a RewriteCond statement to make a rewriterule conditional on whether or not the file exists locally...and then use a proxy or redirect rule to actually make the image available. This does it using a proxy rule:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule /images/(.*\.(png|jpg)) http://dev/images/$1 [P]

This is not actually a tested configuration, but should hopefully point you in the right direction. The mod_rewrite documentation has a detailed description of RewriteCond an RewriteRule, and a Google search for something like rewritecond file exists will get you useful results.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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