Take the 2-minute tour ×

I am using cakephp in one of my projects and my client wants the site URLs to end with .html and not the usual friendly urls. I was wondering if its possible in cakephp to do so through any of its routing techniques. Please help.

share|improve this question
Also see Adding a prefix to every URL in CakePHP –  deceze Aug 5 '10 at 1:42
i suggest u explain to ur client why its important –  Harsha M V Aug 5 '10 at 17:27
It sounds like the client may need more education. I cannot think of any reason why a .html extension would be needed. Can anyone enlighten me? –  Chuck Burgess Aug 6 '10 at 3:43
well its an SEO thing. when the search engine crawler finds a page with an extension of .html it assumes that its a static page and gives it more ranking. i am not sure if this is followed these days by the modern crawlers but my client wants it so i have to give it :) –  Atul Dravid Aug 6 '10 at 22:28
add comment

6 Answers

That is well documented in the cookbook.

UPDATE: 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:

    array('controller' => 'pages', 'action' => 'view'),
        'pass' => array('title')

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

    'Link title',
          'title' => 'super-article', 'ext' => 'html')
share|improve this answer
add comment

One of the parameters you can send to Router::url() (which is called by other methods like HtmlHelper::link() and Controller::redirect()) is 'ext'. Try setting this to 'html'. E.g:

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



If it works, try figuring out a way you can override Router::url() to add it in by default.

share|improve this answer
add comment
up vote 2 down vote accepted

Had to solve this without using Routes. Kept the default route entry for pages:


and in the display action removed the .html extension and rendered the respective view:


While calling the pages added 'ext' to be .html

share|improve this answer
add comment

According to this page you can do something like this

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

but as you are talking about extensions, that may have other consequences.

share|improve this answer
Hi Lucas Heneks, Thanks for the link. I tried it but it doesn't seem to work for me... It giving me the missing controller error. –  Atul Dravid Aug 5 '10 at 11:21
add comment

You will need to associate the html extension to the PHP module in Apache as well. I don't remember exactly the adjustment needed but it will be in /etc/httpd/httpd.conf file. (This file may be in a slightly different place depending on your server's OS.) Just look for the line that associates .php with the PHP module. I believe you may be able to define this in the .htaccess file as well but weather or not you can depends on what you are allowed to do in the httpd.conf file.

share|improve this answer
That won't be necessary since Apache will just route everything through Cake, extension and all, since none of the .html files actually exists. You only need to do what you describe if you have physical HTML files which you want processed by PHP, which is not the case here. –  deceze Aug 5 '10 at 1:41
add comment

As documentation section File extensions says, you could use:


This will tell the router to remove any matching file extensions, and then parse what remains.

share|improve this answer
add comment

Your Answer


