Symfony4 Annotation routing does not work

I found out my mistake. I used the wrong namespace for routing.

use Symfony\Component\Annotation\Route;

It should have been:

use Symfony\Component\Routing\Annotation\Route;

EDIT: I wanted to delete this question but the system wouldn't let me.


I had the same problem with my first Symfony 4 project on a standard apache web server.

Creating a .htaccess file in my public folder fixed the issue.

<IfModule mod_rewrite.c>
    Options -MultiViews
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>

<IfModule !mod_rewrite.c>
    <IfModule mod_alias.c>
        RedirectMatch 302 ^/$ /index.php/
    </IfModule>
</IfModule>

In my case, adding 'apache bundle' solved the problem:

"composer require symfony/apache-pack"

You need this if you run symfony in browser via /public/.