how to use default locale in symfony3.4 routes

Viewed 703

I want to open my websites like these:

So I put this code in routing.yml:

teach:
   resource: "@TeachBundle/Controller/"
   type:     annotation
   prefix:   /{_locale}
   requirements:
       _locale: "|en|fa"

and my controller is like this:

/**
 * @Route("/mrg")
 */
public function mrgAction(Request $request)
{
     $lang=$request->getLocale();

     return new Response("<html><body>Your language: <b> $lang </b></body></html>");
}

All urls worked but http://127.0.0.1:8000/mrg doesn't work and returns:

No route found for "GET /mrg"

I need use default language for example if I try to open http://127.0.0.1:8000/mrg then open http://127.0.0.1:8000/en/mrg.

Is there any solution to fix this problem?

3 Answers
Related