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 directories called v1 and v2. So the user can go to or

v2 has a copy of index.html from v1, and some css files that were never in v1.

v1 has an images directory with hundreds of images in.

If the user goes to v2/images they rightfully get a 404. How do I redirect anything that is not found in the v2 directory to the v1 directory?

Eg: -> -> //does not redirect

(and if it doesn't exist in v1 or v2 it should go to the ErrorDocument for 404 defined in .htaccess?)

Also by user I mean anything, ajax the src of img and script tags, etc.

share|improve this question

Just use RewriteCond. It's described in detail in the apache manual.

<Directory /v2>
   RewriteEngine On
   # if there isnt such a file or directory
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.*)$ /v1/$1

This rewrites (internally) the requests. If you want to redirect the user (HTTP 301), use the [R] flag. You may have issues with RewriteBase in a per directory configuration, just see the manual.

share|improve this answer
I have tried this but it just causes every page on the website (even those not in v1 or v2) to be an error 404. At the top of the htaccess file there is RewriteBase / with a comment from the host saying it is required for the website to work. – Jonathan. Sep 8 '12 at 14:56

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.