Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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,
        ]); 
}

}

?>

like image 234
Kendrick Larlar Avatar asked Mar 05 '20 03:03

Kendrick Larlar


2 Answers

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

like image 129
Faizan Avatar answered Oct 17 '22 07:10

Faizan


apache is missing on you server to add .htaccess file

composer require symfony/apache-pack
like image 22
Mohamed CHIBANI Avatar answered Oct 17 '22 06:10

Mohamed CHIBANI