Friday, September 2, 2011

Remove controller name from url

In cakephp if you want to remove controller name from URL , just add below line on your's routes.php file.

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


its come something like that locahost/stiename/action .

We do this generally to show our static pages on site without controller name in URL , page which are likes about us ,contact us ,help and so on.

4 comments:

  1. thank a lot for your help.. can you please guide how to remove controller and action both as I want yo use url
    From
    http://abc.com/controller/action/parameter
    To
    http://abc.com/parameter

    ReplyDelete
    Replies
    1. Router::connect('aboutus', array('controller' => 'pages','action' => 'cms','aboutus'));

      Delete
    2. array('action' => '/../cms')
      Try This

      Delete
    3. I have tried below method to use just parameter name, but its not working.

      Router::connect('aboutus', array('controller' => 'pages','action' => 'cms','aboutus'));

      Can you please suggest another solution?

      Delete