How can I add .html to all my urls in cakephp?

I use cakephp in one of my projects, and my client wants the site URLs to end with .html, and not regular friendly URLs. I was wondering if it is possible to do this in cakephp using any of its routing methods. Please, help.

+5
source share
7 answers

You have to solve this problem without using routes. Saved default route record for pages:

Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));

and in action, the .html extension was removed on the screen and the corresponding view was displayed:

preg_replace('/\.html$/','',$view);
$this->render(null,'default',$view);

When invoking added pages, 'ext' will be .html

+2
source

cookbook.

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

, :

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

URL-, /page/title -of-page.html, , :

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

, , :

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

, Router:: url() ( , HtmlHelper:: link() Controller:: redirect()), "ext". 'html'. :

echo $this->Html->link('Products', array('controller' => 'products', 'action' => 'index', 'ext' => 'html'));

$this->redirect(array('controller' => 'products', 'action' => 'index', 'ext' => 'html'));

, , Router:: url(), .

+5

-

Router::connect('/(.*).html', array('controller' => 'pages', 'action' => 'display'));

, .

+2

" - ", :

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

, , .

+2

html PHP Apache. , , /etc/httpd/httpd.conf. ( .) , .php PHP. , .htaccess, , , httpd.conf.

0

, app/config/routes.php

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

 Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));

.html.

, .

0

All Articles