Moe Sweet
Moe Sweet

Reputation: 3721

How do I enable SEO-friendly URLs in CakePHP?

I want to do something like www.mydomain.com/page-slug point to www.mydomain.com/custom-pages/view/page-slug, something like Wordpress. How can I do this in CakePHP.

Upvotes: 0

Views: 1684

Answers (1)

jbrass
jbrass

Reputation: 941

you need to modify the Router in app/config/routes.php

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

to

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

There is a big gotcha to this. If your application has any other controllers besides the pages controller which it will, you will have to explicitly declare the routes to the other controllers before the pages controller route like this.

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

so your router should look something like this

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

This was my approach for a site that reqiured seo friendly urls from the root /

Upvotes: 5

Related Questions