1

我正在更改我的应用程序路由,以便可以将子目录与 gTLD (example.com/de/) 一起使用,而不是 URL 参数 (example.com?loc=de)。正如它在http://devzone.zend.com/1765/chaining-language-with-default-route/中一样,我使用了以下路由配置:

protected function _initRoutes() {

    $locale = $this->getResource('locale');

    // Create route with language id (lang)
    $routeLang = new Zend_Controller_Router_Route(
            ':lang', array(
        'lang' => $locale->getLanguage()
            ), array('lang' => '[a-z]{2}')
    );

    // Now get router from front controller
    $front = Zend_Controller_Front::getInstance();
    $router = $front->getRouter();

    // Instantiate default module route
    $routeDefault = new Zend_Controller_Router_Route_Module(
            array(), $front->getDispatcher(), $front->getRequest()
    );

    // Chain it with language route
    $routeLangDefault = $routeLang->chain($routeDefault);

    // Add both language route chained with default route and
    // plain language route
    $router->addRoute('default', $routeLangDefault);
    $router->addRoute('lang', $routeLang);

    // Register plugin to handle language changes
    $front->registerPlugin(new Sistema_Plugin_Language());
}

我正在使用 baseUrl 到整个网站的链接。

但是,我的旧链接(example.com/news/)返回错误消息“没有与请求匹配的路由”,如何强制用户或将用户重定向到新 URL(example.com/en/news/)?

4

0 回答 0