Symfony 4 - route : “The requested URL was not found on this server”

六眼飞鱼酱① 提交于 2020-05-16 01:56:30

问题


this is my first post so i'll try to be understandable.

I am starting with symfony, and there is a problem i can't resolve alone.

This is my controller, and I am working with WAMP. When my Url is "mysite.local", it work normally, and it show me what it should (thanks to the home() function). But when my Url is "mysite.local/hello", i have the following error.

Not Found

The requested URL was not found on this server.

Apache/2.4.41 (Win64) PHP/7.4.0 Server at mysite.local Port 80

I guess this is normal as i didn't created any file named "hello", but it's working in the formation i am following.

Could you help me please ? Thank you

<?php


namespace App\Controller;

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

class HomeController extends AbstractController
{
/**
 * @Route("/hello", name="hello")
 */

public function hello()
{
    return new Response("Bonjour ...");
}
/**
 *@Route("/", name="homepage");
 */

public function home(){
    $prenoms = ["Lior" => 17 , "Joseph" => 12, "Anne" => 55];
    return $this->render("home.html.twig",
        [
            'title' => "Bonjour a tous :)",
            'age' => "31 ",
            'tableau' => $prenoms,
        ]); 
}

}

?>


回答1:


Please try with

mysite.local/index.php/hello

If that works, that means either .htaccess file is missing or mod_rewrite is not enabled on apache server.

first you can run

composer require symfony/apache-pack

to add .htaccess automatically and test, if route works then everything is fine.

otherwise you've to edit httpd.conf or apache2.conf file and enable mod_rewrite




回答2:


apache is missing on you server to add .htaccess file

composer require symfony/apache-pack


来源:https://stackoverflow.com/questions/60537798/symfony-4-route-the-requested-url-was-not-found-on-this-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!