How to setup default routing in Symfony2?
In Symfony1 it looked something like this:
homepage: url: / param: { module: default, action: index } default_symfony: url: /symfony/:action/... param: { module: default } default_index: url: /:module param: { action: index } default: url: /:module/:action/...
I was looking through the cookbook for an answer to this, and think I've found it here. By default, all route parameters have a hidden requirement that they match any character except the / character ([^/]+), but this behaviour can be overridden with the requirements keyword, by forcing it to match any character.
The following should create a default route that catches all others - and as such, should come last in your routing config, as any following routes will never match. To ensure it matches "/" as well, a default value for the url parameter is included.
default_route: pattern: /{url} defaults: { _controller: AcmeBundle:Default:index, url: "index" } requirements: url: ".+"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With