Zend framework 如何在Zend中通过路由阻止目标url?
我在Zend中有一个基本路由,如:Zend framework 如何在Zend中通过路由阻止目标url?,zend-framework,routing,seo,action,router,Zend Framework,Routing,Seo,Action,Router,我在Zend中有一个基本路由,如: url->/faq(控制器faq,默认操作索引) url->/faq/index(控制器faq、操作索引) 这个url应该有相同的内容,一个重复的内容(SEO),我想阻止url/faq/索引并抛出404 如果有人知道怎么做。。。谢谢 您可以随时执行以下操作: public function preDispatch() { if ($this->_request->getActionName() == 'index') {
- url->/faq(控制器faq,默认操作索引)
- url->/faq/index(控制器faq、操作索引)
如果有人知道怎么做。。。谢谢 您可以随时执行以下操作:
public function preDispatch()
{
if ($this->_request->getActionName() == 'index') {
throw new Zend_Controller_Action_Exception;
}
}
但它始终取决于具体情况。您也可以使用路由器():
我发现了一个Apache Url重写的解决方案,如下所示:RewriteRule^(.*)/index[QSA,L,R=301],但如果Zend中有直接的解决方案,我更喜欢它。
// add to your Route file
$Router = Zend_Controller_Front::getInstance()->getRouter();
$Router->addRoute('frotendPage', new Zend_Controller_Router_Route_Static(
'/faq', array(
'module' => 'frontend',
'controller' => 'page',
'action' => 'faq')
));