Answer the question
In order to leave comments, you need to log in
How to correctly move the site root directory to a public subdirectory?
Hello.
All of these newfangled frameworks and "how to do it right" articles (like Create your own PHP Framework ) recommend wrapping all requests to the front controller first, and then moving it to a separate folder (like web or public ). All static files (such as images or style files) are also stored there. For security reasons, allow clients to access only this public folder and deny everything else.
It's just not clear how to do it right. I had an option to create .htaccess in the root of the site
RewriteEngine on
RewriteRule ^web/(.*)$ web/$1 [L]
RewriteRule ^(.*)$ web/$1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ web/index.php
Answer the question
In order to leave comments, you need to log in
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question