I have my application in symfony 2 done.
And now I want to remove the web/app_dev.php/ from the url.
I read about this and after doing this:
php app/console cache:clear --env=prod --no-debug
And add .htaccess:
DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteRule .? %{ENV:BASE}/app.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 302 ^/$ /app.php/
</IfModule>
</IfModule>
After this I can use the url: localhost/test/web/ But it's not exactly my goal. I want to remove the web also.
And after this there's another problem. When I'm using localhost/test/web/ to access the page there's some stylesheet missing, but in app_dev.php everything looks good.
My question is, How can I remove the /web/ from the url? And how can I have the stylesheet missing?
To remove the web you simply have to modify your apache configuration to make web as root directory.
DocumentRoot /yourpath/www/web
<Directory /youpath/www/web/>
Exemple of Apache Virtual Host Complete configuration :
<VirtualHost *:80>
ServerName www.yourdomain.com
DocumentRoot /yourpath/www/web
<Directory /yourpath/www/web>
Options FollowSymLinks
AllowOverride None
Require all granted
Allow from All
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /app.php [QSA,L]
</Directory>
LogLevel warn
ErrorLog ${APACHE_LOG_DIR}/your_site.error.log
CustomLog ${APACHE_LOG_DIR}/your_site.log combined
</VirtualHost>
In production you should remove app_dev.php and set as root directory symfony web folder
Note: I don't add <IfModule mod_rewrite.c></IfModule> because if you don't have it you want apache to inform you that you are missing this module.
To remove the /web part you can set RewriteBase additionally
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /web/
...
... or set your DocumentRoot directly to the web folder in your apache VirtualHost configuration.
The missing stylesheet in the prod environment can be resolved by invoking the assets:install command.
In the dev symfony will serve the files directly from the bundle's Resources/public folders because the default config_dev.yml contains assetic.use_controller: true.
The default production configuration has assetic.use_controller: false for performance reasons. Assets will not be recompiled and served through symfony on every request.
Now the assets in a bundle's Resource folder are not accessible until they are being moved/symlinked to the web folder where your webserver can find them which the assets:install and assetic:dump commands do.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With