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]
link|improve this question
My example is working. The problem was the AllowOverride None in the server main configuration file. – Walkman Jan 22 at 18:22
It doesn't exactly do the described behavior though. It first check the file and rewrite if exists. – Walkman Jan 22 at 18:28
feedback

1 Answer

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

Your Answer

 
or
required, but never shown

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