无法访问我的Symfony控制器@Route

I'm new with Symfony (using version 3.4). And I'm using it with XAMPP on macOS High Sierra. I set my vhosts like this:

<VirtualHost *:80>
   DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/project/web/app_dev.php"
   ServerName project
</VirtualHost>

And set my hosts file with "127.0.0.1 project" and that works fine.

But then in my application I created a Controller:

<?php

namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;

class ProjectController extends Controller
{ 
    /**
    * @Route("/todo", name="todo_list")
    */
    public function indexAction(Request $request)
    {
        die("TO DOS");
        // replace this example code with whatever you need
        return $this->render('default/index.html.twig', [
            'base_dir' => realpath($this- 
            >getParameter('kernel.project_dir')).DIRECTORY_SEPARATOR,
         ]);
    }
}

but when I access to project/todo it redirects to project/dashboard and shows XAMPP welcome page. How can I go to project/todo ?

NOTE: Although I'm using Mac I'm doing this tutorial https://www.youtube.com/watch?v=HchMW8EhWPU

I had limited experience with Apache + Symfony, but I believe your DocumentRoot is incorrent. You should point to web directory instead of your prod or dev front controller. For the testing purposes, just remove the app_dev.php from the very end. Did that help?

Based on your version, always consult official docs, like this one: Configuring a Web Server

In order to debug your routes, I suggest your run bin/console debug:router in order to gather better insight in you registered routes.

Hope this helps a bit...

Your document root is incorrect. The document root must always be a directory. So your document root should be:

DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/project/web/"

Next: What you want is that all requests go through app_dev.php. This is accomplished by rewrite rules. Rewrite rules map the client’s request to a real resource, in your case the app_dev.php front controller.

Here’s a set of rewrite rules which should work for you. (I’m currently not using Apache, so I dug them up from a legacy project and hope they work for you.) Put this into a .htaccess file into your web/ directory:

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

This is a basic set of rules, basically meaning that the webserver should rewrite all requests for non-existent files to app_dev.php.

You can also add it to the webserver configuration, but then you have to restart your webserver each time you modify the configuration.

Also: If, for some reason, you get 5xx errors after modifying your configuration, look into the server logs for explainations.