使用 Zend 框架,我正在尝试构建一个对 SEO 友好的 URL
http://ww.website.com/public/index/categories/category/2
应该由http://ww.website.com/public/index/categories/category.html
http://ww.website.com/public/index/products/category/2/subcategory/2
应该由http://ww.website.com/public/index/products/product.html
在我的引导文件中,我尝试过这个
protected function _initRoutes()
{
$frontController = Zend_Controller_Front::getInstance ();
$router = $frontController->getRouter ();
$route = new Zend_Controller_Router_Route_Regex(
'index/categories/category/(\d*)/',
array('module' => 'default','controller' => 'index','action' => 'categories'),
array(1 => 'category'),
'index/categories/%d-%s.html');
$router->addRoute('category', $route);
}
现在我的问题是如何重写这个 URL?我还使用以下方法根据 URL 中的 ID 检索产品或类别:
$id = $this->_getParam('category', 0 );
任何人都可以帮助我吗?