php - 如何将 .html 附加到 cakephp 中的所有 URL?

标签 php cakephp routing url-rewriting

我在我的一个项目中使用 cakephp,我的客户希望网站 URL 以 .html 结尾,而不是通常的友好 URL。我想知道在 cakephp 中是否有可能通过它的任何路由技术来做到这一点。请帮忙。

最佳答案

这在 cookbook 中有详细记录.

更新:http://book.cakephp.org/2.0/en/development/routing.html#file-extensions

To handle different file extensions with your routes, you need one extra line in your routes config file:

Router::parseExtensions('html', 'rss');

If you want to create a URL such as /page/title-of-page.html you would create your route as illustrated below:

Router::connect(
    '/page/:title',
    array('controller' => 'pages', 'action' => 'view'),
    array(
        'pass' => array('title')
    )
);

Then to create links which map back to the routes simply use:

$this->Html->link(
    'Link title',
    array('controller' => 'pages', 'action' => 'view', 
          'title' => 'super-article', 'ext' => 'html')
);

关于php - 如何将 .html 附加到 cakephp 中的所有 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3410611/

相关文章:

php - undefined variable argc PHP

cakephp - 如何在CakePHP中更新1个字段?

url - Symfony2 - 每个地区的网址

performance - 我应该在路由逻辑还是 Meteor Template Helper 中提供数据?

php - Codeigniter 查询中的动态分配值类型过滤器

php - PHP include_path 是否使用工作目录作为后备?

php - 仅获取每个类别的随机项目

php - cakephp 模型中的电子邮件验证

ruby - 如何从 Rake 文件、Make 文件或它们的组合调用 Cake 文件?

routing - RestKit 0.20.2 路由和映射