zend-framework - Zend 框架 : How to 301 redirect old routes to new custom routes?

标签 zend-framework redirect http-status-code-301

我有大量旧路线,需要将其重定向到新路线。

我已经在 Bootstrap 中定义了我的自定义路由:

protected function _initRoutes()
{
    $router = Zend_Controller_Front::getInstance()->getRouter();

    $oldRoute = 'old/route.html';
    $newRoute = 'new/route/*';

    //how do I add a 301 redirect to the new route?

    $router->addRoute('new_route', 
        new Zend_Controller_Router_Route($newRoute,
            array('controller' =>'fancy', 'action' => 'route')
    ));
}

如何添加使用 301 重定向将旧路由重定向到新路由的路由?

最佳答案

我就是这样做的

  1. 添加 Zend_Route_Regexp 路由作为旧路由
  2. 为旧路由添加 Controller 和操作
  3. 添加逻辑来解析旧路由
  4. 为此逻辑添加 $this->_redirect($url, array('code' => 301))

关于zend-framework - Zend 框架 : How to 301 redirect old routes to new custom routes?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4229204/

相关文章:

linux - github项目与本地服务器同步问题

Magento如何停止/结账/单页/成功/重定向

http - ERR_TOO_MANY_REDIRECTS 错误你

由于浏览器缓存,PHP header 301 重定向不起作用

seo - 301重定向和SEO

php - Twitter Bootstrap 框架和 Zend 框架

zend-framework - Zend 搜索 Lucene 和重音字符

php - 我是在重新发明轮子吗? PHP/Mysql用户注册及支付处理

javascript - 使用 window.location 重定向到应用程序商店

Grails Controller 重定向和 SEO