Placement of a project on the Symfony framework on the server
As you know from the lessons, the public directory of Symfony framework by default is web/, and the framework directories lie next to it. This means that for normal operation and pretty URLs, the DocumentRoot on the server should be set specifically to the web/ folder. But this is not always convenient and not always possible on hosting. In most cases, you will not have the ability to edit the DocumentRoot.
There are at least 2 ways to solve this problem.
The first one. Not quite elegant, but it works. You need to configure modrewrite via .htaccess in such a way as to redirect addresses like http://site/url -> http://site/web/url. It is done as follows:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ web/$1 [L,QSA]
</IfModule>
In principle, it will do, but web in the URL somehow doesn't look right =) The second one. In order to get more pretty and natural URLs, it is sufficient to move the contents of the web/ directory to the root directory (httpdocs or another one depending on the settings), but you need to specify the new location of the entry scripts in Symfony framework:
//app.php
$loader = require_once __DIR__.'/app/bootstrap.php.cache';
...
require_once __DIR__.'/app/AppKernel.php';
Instead of the default ones:
$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
...
require_once __DIR__.'/../app/AppKernel.php';
That's basically it. Just don't forget to change the installation directory for assets during subsequent updates (now they should be placed in the root, not in web/):
php app/console assets:install --env=prod .
php app/console assetic:dump --env=prod .
Also, it won't hurt to replace IndexDirectory in .htaccess:
DirectoryIndex app.php