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

I have a public folder in my document root. I would like to redirect all the files that are not present in document root, but are present in the public folder. (So if the same file is in two places, the file that is not in the public will be served first.)
How can I do this ?
The following doesn't work:

RewriteCond %{DOCUMENT_ROOT}/public/%{REQUEST_URI} -f¬
RewriteRule ^(.*)$ public/$1 [QSA, PT, L]
share|improve this question
    
My example is working. The problem was the AllowOverride None in the server main configuration file. –  Walkman Jan 22 '12 at 18:22
    
It doesn't exactly do the described behavior though. It first check the file and rewrite if exists. –  Walkman Jan 22 '12 at 18:28

1 Answer 1

up vote 3 down vote accepted
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1
share|improve this answer
    
perfect ! thanks –  Walkman Jan 22 '12 at 18:28
    
however I suggest to make an other RewriteCond too RewriteCond %{REQUEST_FILENAME} !-d for directories –  Walkman Jan 23 '12 at 9:28

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.