1

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

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

Piotr Pogorzelski
  • 1,286
  • 7
  • 18

1 Answers1

2

Short and sweet... I think you just need to add a second route.

'blog/archive' => 'controller/action/path',
'blog/archive/<year:\d{4}>' => 'controller/action/path'
Lindsey D
  • 23,974
  • 5
  • 53
  • 110