<p>Short and sweet... I think you just need to add a second route.</p>

<pre class="lang-php prettyprint-override"><code>'blog/archive' =&gt; 'controller/action/path',
'blog/archive/&lt;year:\d{4}&gt;' =&gt; 'controller/action/path'
</code></pre>

CC BY-SA 4.0
2020-04-24T14:59:22.507Z
2020-04-24T14:59:22.507Z
Lindsey D
<p>I have a question about custom routes set in <code>routes.php</code>. Can route segment be optional?</p>

<p>Taking example from docs - <code>'blog/archive/&lt;year:\d{4}&gt;' =&gt; 'controller/action/path'</code>, can we make year token optional in url and still match route when someone vists <code>blog/archive</code>?</p>

<routes>
Custom route with optional tokens
# Custom route with optional tokens

(Asked by: username_0 on 2020-04-24)

I have a question about custom routes set in `routes.php`. Can route segment be optional?

Taking example from docs - `'blog/archive/' => 'controller/action/path'`, can we make year token optional in url and still match route when someone vists `blog/archive`?

**Tags:** routes


---

## 1 answers

### Answer by username_1 on 2020-04-24. Score: 2 | Accepted answer

Short and sweet... I think you just need to add a second route.
'blog/archive' => 'controller/action/path',
'blog/archive/' => 'controller/action/path'


---

