如何在 CakePHP 中启用 SEO 友好的 URL?

发布于 2024-09-17 10:45:31 字数 155 浏览 2 评论 0原文

我想做一些像 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ま柒月 2024-09-24 10:45:57

您需要将 app/config/routes.php 中的路由器修改

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

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

这有一个很大的问题。如果您的应用程序除了页面控制器之外还有任何其他控制器,则必须在页面控制器路由之前显式声明其他控制器的路由,如下所示。

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

所以你的路由器应该看起来像这样

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

这是我的方法,用于需要来自根/的 seo 友好 url 的网站

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 /

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文