views:

17

answers:

1

I have moved all files from a project that should be accessible from outside to a single public directory - so that instead of blacklisting directories that must remain hidden, I could whitelist accessible ones.

However I cannot force apache to rewrite this kind of urls:

  • www.example.com/images/flower.jpg

to fetch

  • <DOCUMENT ROOT>/public/images/flower.jpg

Only rational solution I came up with was something among those lines:

RewriteCond public\/%{REQUEST_FILENAME} -f #if a file exists in the public dir,...
RewriteRule .* public/$0 [L]               #display it

Unsurprisingly, it does not work, more precisely, the RewriteCond part, I can't get it to match.

I am completely at loss, could someone help?

As a side question, how do you debug .htaccess configurations? I can't fix the problem if I don't know what and where it is.

+1  A: 

If you want to test for an existing file with -f, you need to provide an absolute file system path like this:

RewriteCond %{DOCUMENT_ROOT}/public%{REQUEST_URI} -f
RewriteRule !^public/ public%{REQUEST_URI} [L]

Otherwise use -F to do the check via a subrequest:

RewriteCond public%{REQUEST_URI} -F
RewriteRule !^public/ public%{REQUEST_URI} [L]
Gumbo