I’m having some problems with mod rewrite in the following configuration (simplified version):
/index.php
/public/
/public/file.txt
I need to remap the site root to the /public so i can call /file.txt for every existing file in /public. In the same time, every non-existing file should be remapped to index.php which is not in the /public folder.
I have previously solved this issue by using:
RewriteCond %{DOCUMENT_ROOT}/public%{REQUEST_URI} -f
RewriteRule ^(.*)$ public/$1 [L]
RewriteRule ^(.*)$ index.php?$1 [L]
the only problem is that it only works if the site and the .htaccess is in the server root directory. What I need is to make it work if the site is in the /codeigniter/ directory
/codeigniter/index.php
/codeigniter/public/
/codeigniter/public/file.txt
which obviously fails because
/public%{REQUEST_URI}
translates into
/public/codeigniter/public/ which doesn't exist
I’ve tried setting the rewriteBase to the /codeigniter/ directory but I think it only strips the dir in the rewrite Rule and not in the RewriteCond since it doesn’t work.
I think that an idea would be to map everything to the /public folder and in /public/.htacces re-remap non existent files to ../index.php (not sure if it’s possible)
I would really apreciate any help you can give me with this, since it’s an older problem I’m constantly facing. Ideally, the path should not be hardcoded in the .htaccess so I can easily move or rename the site folder without changing the .htaccess
Cheers
After struggling for a few hours with it I finaly found the answer:
in the /codeigniter/.htacces we need theese lines:
And we need a second “almost empty” .htaccess in /codeigniter/public with just one line:
Now I have my site root protected from remote access and my public folder’s name hidden from links. Also, I can rename or move my /codeigniter folder anyway I like without requiring any modifications in .htaccess
Good day to you all