我知道我以前见过这样做,但我在任何地方都找不到信息。我需要能够在 Zend Framework 中使用 .html 扩展名进行路由。
IE。 /controller/action.html 应路由到适当的控制器/操作。
我们有一个想法,用 .htaccess 文件丢弃 .html 扩展名,但我认为更改路由配置将是更好的解决方案。
欢迎任何建议。
这是我在多个应用程序中使用过的插件:
/**
* Removes .html extension from URI, if present.
*/
class Application_Plugin_RemoveHtmlExtension extends Zend_Controller_Plugin_Abstract
{
public function routeStartup(Zend_Controller_Request_Abstract $request)
{
// remove ".html" from the end of the URI
$url = preg_replace('#\.html$#i', '', $request->getRequestUri());
$request->setRequestUri($url);
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)