Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have directories called v1 and v2. So the user can go to http://example.com/v1 or http://example.com/v2.

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:

http://example.com/v2/someotherfile.html -> http://example.com/v1/someotherfile.html 
http://example.com/v2/images/base.jpg -> http://example.com/v1/images/base.jpg 
http://example.com/v2/index.html //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

1 Answer 1

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
</Directory>

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

 
discard

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.