How to rewrite using htaccess if the file exists in another folder?

Posted by Jack on Server Fault See other posts from Server Fault or by Jack
Published on 2013-11-13T15:55:02Z Indexed on 2013/11/13 15:58 UTC
Read the original article Hit count: 231

Filed under:
|
|

We are trying to rewrite to another folder if the file does not exist in the document root, but does exist in the other folder.

The other folder is in a completely different location, which is located using "Alias" in the vhosts.

So, what we have so far (from this post How to rewrite URI from root if file exists in folder?) is:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/legacy/
RewriteRule ^(.*)$ legacy/$1 [QSA,L]

This works to an extent, but seems to direct everything to the legacy folder, not just when the file doesn't exist in the first location and does exist in legacy.

Thanks in advance for any help, Jack.

© Server Fault or respective owner

Related posts about .htaccess

Related posts about rewrite