Zend框架 - 如何重写URL以搜索引擎友好的URL
我得到了Zend框架(Zend公司中的总IM小白)的网站。例如,我想提出一个网址 somewebsite.com/test/about
来看待这样的 somewebsite.com/for-fun-link
。如何在Zend公司实现这一目标?林新手在Zend和Apache服务器。我哪里做的Zend重写?我想静态URL的 somewebsite.com/page/about 改写为 somewebsite.com/about-product
I got website on Zend Framework (im total noob in Zend). For example I would like to make one URL "somewebsite.com/test/about
" to look like this "somewebsite.com/for-fun-link
". How do i achieve this in Zend ? Im newbie in Zend and Apache server. Where i do rewrites in Zend ? I want static URL somewebsite.com/page/about rewrite to somewebsite.com/about-product
和最后一个问题:在哪里我通常创建重写?它取决于SEVER /技术?
And last question: where do i usually create rewrites ? its depends of sever/technology ?
在你的引导,你需要配置一些路线。所以,如果你的引导程序结束这样的:
In your bootstrap, you'll need to configure some "routes". So, if your bootstrap ends something like this:
$frontController = Zend_Controller_Front::getInstance();
$frontController->dispatch();
你可以加入一些路由定义是这样的:
you can just add in some route definitions like this:
$frontController = Zend_Controller_Front::getInstance();
$router = $frontController->getRouter();
$router->addRoute( 'mylovelyroute',
new Zend_Controller_Router_Route_Static( 'for-fun-link',
array( 'controller' => 'test', 'action' => 'about' )
)
);
$router->addRoute( 'myotherroute',
new Zend_Controller_Router_Route_Static( 'about-product',
array( 'controller' => 'page', 'action' => 'about' )
)
);
$router->addRoute( 'justonemore',
new Zend_Controller_Router_Route_Static( 'another/longer/path',
array( 'controller' => 'mycontroller',
'action' => 'myaction',
'someparameter' => 'foo'
)
)
);
$frontController->dispatch();
addRoute的第一个参数()
只是一个唯一的名称。 Zend_Controller_Router_Route_Static
将您想拍摄的路径,然后参数数组,其中包括一个控制器和动作(如果适用模块)。
The first parameter of addRoute()
is just a unique name. Zend_Controller_Router_Route_Static
takes the path you'd like to capture, and then an array of parameters, including a controller and action (and module if it applies).
如果你想增加复杂性,你可以加载路由从数据库中,或开始使用更多的动态路由。这里的文档是一个有用的下一个步骤:http://framework.zend.com/manual/en/zend.controller.router.html#zend.controller.router.routes.standard
If you wanted to add complexity, you could load the routes out of a database, or start using more dynamic routes. The docs here are a useful next step: http://framework.zend.com/manual/en/zend.controller.router.html#zend.controller.router.routes.standard