Feb 05 2011

Redirecting from an old route in Zend Framework

Firstly ensure your old route has been created:

routes.new.route = "new"
routes.new.defaults.controller = index
routes.new.defaults.action = new
routes.new.defaults.module = default
routes.new.defaults.id = ""
routes.new.reqs.id = \d+

routes.old.route = "old"
routes.old.defaults.controller = index
routes.old.defaults.action = old
routes.old.defaults.module = default
routes.old.defaults.id = ""
routes.old.reqs.id = \d+

In the controller:

class IndexController extends Zend_Controller_Action 
{
    ...

    public function oldAction()
    {
        $redirector = $this->_helper->getHelper('Redirector');
        $redirector->setCode(301);
        return $redirector->gotoRoute($this->_getAllParams(), 'new');
    }
}

For reference, examples developed with Zend Framework 1.11.2

comments powered by Disqus

Info

I'm Ade Slade, a PHP web developer.