Search code examples
.htaccesssymfonymod-rewriteapache2front-controller

new Symfony project on apache server needs mod_rewrite code?


I have just created a new (test) symfony project and set my apache webroot to /home/user/project/ (not sure if it should be /home/user/project/web/?)

However, from what I understand based on the lightbulb section here: http://symfony.com/doc/current/book/page_creation.html#the-web-directory - there isn't any internal rerouting occurring. Therefore, this does not work:

http://localhost/random/10

but these do work:

http://localhost/app_dev.php/random/10
http://localhost/app.php/random/10

To double check, if I start the internal PHP server (php app/console server:start) then everything gets rerouted correctly - this does work:

http://localhost:8000/random/10

Am I right in thinking that I need to make changes to .htaccess? If so, is there a 'standard' section of code for using apache with symfony?

EDIT: I have updated my apache2.conf (which for others would be httpd.conf if not on ubuntu as I understand it) as below:

<Directory /home/user/Project/>
    Options Indexes FollowSymLinks
    AllowOverride All 
    Require all granted
</Directory>

Solution

  • If I remember correctly, .htaccess alredy defines DirectoryIndex as app.php. However, your Apache config file httpd.conf might be blocking the override.

    Make sure that you have that line in your .htaccess and also check the value of AllowOverride (docs) within your httpd.conf. Try setting AllowOverride to All and see if that works.