How can I move the literal part of the route to the end like this
/:rubric-rb/[:page], i.e. how to tell the route plugin to match the literal part first? Or if I were to use the regex plugin how to make a part of the spec optional?
'rubric' => [
'type' => Segment::class,
'options' => [
'route' => '/rb-:rubric/[:page/]',
'constraints' => [
'rubric' => '[a-zA-Z0-9_-]+',
'page' => '[0-9]+',
'defaults' => [
'controller' => Controller\IndexController::class,
'action' => 'rubric',
Currently I’m using a halfway solution: making the segment optional, that way it gets matched after the literal part, but I think this is not ideal because it doesn’t indicate the intended purpose.
you can use
Literal route type as your base route and define one or more child routes, there you can use
Segment route type to define other routes with some optional and required segments including actions,controllers and other desired parameters.
Regex route type if you don’t want to utilize the common way you can define your own route type.
check out documentation of zf3 into understanding the Router.