72014Jul
Cake PHP Url Rewriting

Cake PHP Url Rewriting

CakePHP Url Rewriting

Some developers don’t like CakePhp Url structure because controller name should end with “s” and that cause a lot of dissatisfaction fro developers while developing with cakephp.

For this CakePhp provides a simple and effective way to rewrite url in seo friendly way and according to client requirement.

So how to write code for it. Here is the simple example.

Go to app -> config -> routes.php

Add the following code

.
.
      Router::connect('/contact-us', array('controller' => 'messages'));
.
.

Above code simply render the request for “/contact-us” to “messages” controller .

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

And this code render the request for “pages” controller with action “display” with parameter “terms” to “/terms”.

For more information go to Cake Docs