In my CakePHP 2.3 application, I want example.com/come/Harry
to redirect example.com/myworks/people/Harry
.
This works, but this connects.
Router::connect ('/come/:myname',
array('controller' => 'myworks', 'action' => 'people'),
array(
'pass' => array('myname')
)
);
I need a 301 redirection. I tried this:
Router::redirect ('/come/:myname',
array('controller' => 'myworks', 'action' => 'people'),
array(
'pass' => array('myname')
)
);
But it redirected to example.com/myworks/people/
. How can I pass argument to my action while redirecting ?
Per the documentation you want to use
persist
rather thanpass
for redirects. This code should work as you want:The reason is because you're generating a new url when you redirect:
Use following code
You are pretty much there, but you need to define your named params so that cake knows that the url is valid.
Reference, http://book.cakephp.org/2.0/en/development/routing.html#passing-parameters-to-action