如何在CakePHP中启用SEO友好的URL?
我想做 www.mydomain.com/page-slug
,指向 www.mydomain.com/custom-pages/view / page-slug
,类似Wordpress。如何在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.
您需要在app / config / routes.php
you need to modify the Router in app/config/routes.php
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
到
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 /