如何在CakePHP中启用SEO友好的URL? [英] How do I enable SEO-friendly URLs in CakePHP?

查看:112
本文介绍了如何在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 /

这篇关于如何在CakePHP中启用SEO友好的URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆