Strange problem with redirect and routing -> results in a loop (CakePHP 2.8.6)


Ive a strange problem with a redirect to the same controller/action but with different routes:

The following routes are definded:

Router::connect(’/service/manuals’, array(‘controller’ => ‘manuals’,‘action’ => ‘index’,‘language’ => ‘eng’ ));
Router::connect(’/service/manuals/:year’, array(‘controller’ => ‘manuals’,‘action’ => ‘index’,‘language’ => ‘eng’ ),array(‘year’ => ‘[12][0-9]{3}’,‘pass’ => array(‘year’)));

And in my controller ‘manuals/index’ I have the following redirect:

public function index($year = null) {
if (empty($year)) {
$this->redirect(array(‘controller’ => ‘manuals’, ‘action’ => ‘index’, ‘year’ => 2016));

This ends up in a redirect loop :frowning: Calling index without any arguments should trigger the redirect to the same function with the year set (so the redirect should not be called again). Whats wrong here?

The routes do work as they should (tried manually). Only the redirect causes problems…

By the way - is it possible to combine the two routes above to a single one? So year is fully optional. Ive tried everything, but I had only success seperating this into two routes.

Thanks for your help,

Why don’t you change the $year value to 2016 when it’s empty, instead of making a redirection ?