I have a certain PHP application written with the Silex framework. I built the structure in a way where only the public
folder would be the folder where I would point Apache to read it.
My structure is more or less this:
projeto/
app/
resources/
public/
css/
js/
img/
index.php
vendor/
So, in my Apache Virtualhost, I would have to point to projeto/public
, as this would be the root of my site.
But the blessed one on my server is a shared host, so I can not point to public
folder at all.
On this shared host server, the read is made from the public_html
folder, and there is no chance of me putting the public
folder.
I want to use the public_html
folder to be the root by adding the files that are inside my projeto
(local development) folder.
public_html/
app/
resources/
public/
css/
js/
img/
index.php
vendor/
I intend to use the framework. I know there is a way to direct everything that is accessed at the root to public/index.php
I'm doing this:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ public/index.php [L]
I have not purposely used !-d
since I do not want anyone to access app
and look at the directory. And I also have a routing system within index.php
that could read app/
as an application route (not as a folder).
The problem is that if I access app/routes.php
for example, an error page will appear because this file should not be accessed, but only the public
folder.
I want to know if in .htaccess
is there any way to redirect everything absolutely to a specific folder.
I want my .htaccess
to make apache recognize public_html/public
as root, instead of public_html
.
I want access to public/css/default.css
to be rewritten to css/default.css
. And I do not want other folders like vendor
, resources
and app
to be accessible.
That is, I always want public_html/public
to be accessed as root.
Can you do this?
I tried to RewriteRule ^ public/index.php [L]
without RewriteCond {REQUEST_FILENAME} !-f
and ended up giving an internal error (due to recursion generated).