# Zend-router, help with route definition?

**URL:** <https://discourse.laminas.dev/t/zend-router-help-with-route-definition/400>\
**Category:** Components & MVC\
**Created:** [December 13, 2017, 12:07pm UTC](https://discourse.laminas.dev/t/zend-router-help-with-route-definition/400 "2017-12-13T12:07:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![eugpavl](https://avatars.discourse-cdn.com/v4/letter/e/e68b1a/32.png) [@eugpavl](https://discourse.laminas.dev/u/eugpavl)\
**Post date:** [December 13, 2017, 12:07pm UTC](https://discourse.laminas.dev/t/zend-router-help-with-route-definition/400/1 "2017-12-13T12:07:52Z")

</div>

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?

```auto
            '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',
                    ],
                ],
            ],

```

---

<div class="post-metadata">

**Author:** ![eugpavl](https://avatars.discourse-cdn.com/v4/letter/e/e68b1a/32.png) [@eugpavl](https://discourse.laminas.dev/u/eugpavl)\
**Post date:** [December 15, 2017, 9:07am UTC](https://discourse.laminas.dev/t/zend-router-help-with-route-definition/400/2 "2017-12-15T09:07:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![erfan](https://avatars.discourse-cdn.com/v4/letter/e/c4cdca/32.png) [@erfan](https://discourse.laminas.dev/u/erfan)\
**Post date:** [December 15, 2017, 4:56pm UTC](https://discourse.laminas.dev/t/zend-router-help-with-route-definition/400/3 "2017-12-15T16:56:26Z")

</div>

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.  
For `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](https://docs.zendframework.com/tutorials/in-depth-guide/understanding-routing/).
