Two month ago I asked, how to realize the routing with language parameter in uri here: Locale in Routing, Default Language also without Parameter
But now, to avoid double content, I want to have the default language (en) without and other languages with parameter. In other words i need to define the route-prefix according to the _locale parameter.
Example
http://example.com/
http://example.com/de/
http://example.com/about/
http://example.com/de/about/
...
Here is my testing setup, which gives me the error show below:
routing.yml:
_site_en:
resource: "@MyMainBundle/Controller/SiteController.php"
type: annotation
requirements: { _locale : en }
prefix: /
_site:
resource: "@MyMainBundle/Controller/SiteController.php"
type: annotation
requirements: { _locale : fr|es|it|de }
prefix: /{_locale}/
Controller Annotations
/**
* @Route( "/", name="_site_startpage", defaults={"_locale" = "", "slug"="startpage"} )
* @Route("/{slug}/", name="_site_site", defaults={"_locale"=""})
*
* @ParamConverter("page", class="MyMainBundle:Page")
*/
public function siteAction( $slug, $_locale, Page $page )
How to do it the right way?
Edit: As a Result I get an Exception, that the Route to the path is not defined.
No route found for "GET /"
404 Not Found - NotFoundHttpException
1 linked Exception:
ResourceNotFoundException »
router:debug only shows the 2nd route:
_site_startpage ANY /{_locale}/
_site_site ANY /{_locale}/{slug}/
Edit 2: I ended up using the JMSI18nRoutingBundle…