开发者

How do I enable SEO-friendly URLs in CakePHP?

I want to do something like www.mydomain.com/page-slug po开发者_开发技巧int to www.mydomain.com/custom-pages/view/page-slug, something like Wordpress. How can I do this in CakePHP.


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 /

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜