How to remove “web/app_dev.php” from Symfony2 URLs?

前端 未结 7 1150
误落风尘
误落风尘 2020-12-13 07:01

I just created my first Symfony2 project. But the \"/web/app_dev.php\" part in the URL annoys me. It should be possible to do this without Virtual hosts...

7条回答
  •  隐瞒了意图╮
    2020-12-13 07:44

    Symfony2 comes with a built in debug mode, which is what you are using when you access url's with the app_dev.php addition. The debug mode caches significantly less than the production mode which can be accessed by directing your browser to the url, but leaving out the app_dev.php. If accessing this url doesn't work then it probably means that you need to clear your production cache.

    To clear the cache direct you terminal (command console) to the root of you Symfony project. From there type the following command:

    php app/console cache:clear --env=prod --no-debug
    

    Per comments below in Symfony 3 this has moved:

    php bin/console cache:clear --env=prod --no-debug
    

    This should clear your productions cache and allow you to access urls without the app_dev.php.

    As for the web part of the url. The easiest way to remove that is to set the web root of your project to the web folder. It's best to do this with apache using virtual hosts, but there are ways to do it with the htaccess.

    This link explains how to use the htaccess file to change the webroot. http://kb.siteground.com/how_to_change_my_document_root_folder_using_an_htaccess_file/

    Hope this helps!

提交回复
热议问题