Routing not working in Symfony 3.4

Well, as @Basel Issmail pointed out, Symfony/Flex doesn't create a .htaccess like the previous Symfony installer did, and I had forgotten it.

I just had a minimal Apache configuration file:

<VirtualHost *:80>
    DocumentRoot /path/to/my-project/public
    ServerName myproject.localhost

    <Directory /path/to/my-project/public>
        Options -Indexes +FollowSymLinks -MultiViews
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

So I created the .htaccess file in /public/ (where the index.php file lies), and the minimal required configuration is something like:

<IfModule mod_rewrite.c>
    RewriteEngine On

    # Determine the RewriteBase automatically and set it as environment variable.
    RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
    RewriteRule ^(.*) - [E=BASE:%1]

    # If the requested filename exists, simply serve it.
    # We only want to let Apache serve files and not directories.
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule .? - [L]

    # Rewrite all other queries to the front controller.
    RewriteRule .? %{ENV:BASE}/index.php [L]
</IfModule>

The missing part was to rewrite all queries (except existing files like assets) to index.php, for Symfony to handle the route.

--- Edit ---

Instead of manually creating the .htaccess, you can also just use a symfony flex recipe:

composer require apache-pack

This will install this .htacess file.


Sounds like you need to setup your RewriteBase with apache, since the problem is not at /

Maybe .htaccess file is even missing since you are using Symfony/flex, and it doesn't add it by default like previous Symfony editions.

Check this page to configure a Web Server

.htaccess should be inside public folder and The minimum configuration to get your application running under Apache is:

<VirtualHost *:80>
    ServerName domain.tld
    ServerAlias www.domain.tld

    DocumentRoot /var/www/project/public
    <Directory /var/www/project/public>
        AllowOverride All
        Order Allow,Deny
        Allow from All
    </Directory>

    # uncomment the following lines if you install assets as symlinks
    # or run into problems when compiling LESS/Sass/CoffeeScript assets
    # <Directory /var/www/project>
    #     Options FollowSymlinks
    # </Directory>

    ErrorLog /var/log/apache2/project_error.log
    CustomLog /var/log/apache2/project_access.log combined
</VirtualHost>