How do I enable SEO-friendly URLs in CakePHP?

喜你入骨 提交于 2019-12-10 12:08:28

问题


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.


回答1:


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 /



来源:https://stackoverflow.com/questions/3646170/how-do-i-enable-seo-friendly-urls-in-cakephp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!