My project directory structure:
project_root/
|- src/
| |- model/
| |- view/
| |- controller/
| -- ...others
-- resources/
|- css/
|- js/
-- images/
Ok, somewhere in src
there is a file responsible for redirecting controllers, views and so on, let us say it is the src/url_mapping.php
, it is prepared to solve any kind of url, such as /{controller}/{action}/{id}?{query}
, there is no problem here, the big deal is I do not want the user realize this folder structure exists, I want to hide it from them and let the flow as simples as RoR and other based systems.
I want allow only http://host/{css,js,images}/*
from resources
without allowing http://host/resources/*
itself, and http://host/{controller}/{action}/{id}?{query}
to the src/url_mapping.php
file denying direct access to http://host/src
.
For now, the closest I managed is the following .htaccess
file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{DOCUMENT_ROOT}/resources/$1 !-f
RewriteCond %{DOCUMENT_ROOT}/resources/$1 !-d
RewriteCond %{DOCUMENT_ROOT}/resources/$1 !-l
RewriteRule (?!^resources/|^src/url_mapping.php/)^(.*)$ src/url_mapping.php/$1 [L,PT]
RewriteCond %{DOCUMENT_ROOT}/resources/$1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/resources/$1 -d [OR]
RewriteCond %{DOCUMENT_ROOT}/resources/$1 -l
RewriteRule (?!^resources/)^(.*)$ /resources/$1 [L,PT]
</IfModule>
In that case my first intention was: If users tries to get /resources
or /src
folder it will be filtered by src/url_mapping.php
as well, although I am trying several combinations with no success over and over again.
I noted mod_rewrite
are in loop such a way I can not block resources
directory as well as src/url_mapping.php
, I am limited to .htaccess
file with my hands tied, but if there is another way to do that I will accept the solution.
The last choice is do only one redirect and treating even files in resources
by src/url_mapping.php
, but it will kill the cache, I am avoiding reinvent the wheel.