如何在没有ID的CakePHP中使用SEO网址?

时间:2010-07-14 09:37:20

标签: cakephp seo routes url

是否有一种简单的方法来路由我的网址而不在网址中显示ID。例如,我有:

www.mywebsite.com/id-article-title.html我只想www.mywebsite.com/article-title.html

此致

2 个答案:

答案 0 :(得分:2)

将url列添加到db表中。然后你可以做findByUrl()。如上所述,它有很好的记录。

function view($url = null) {
    if (!$url) {
        $this->Session->setFlash('Invalid url');
        $this->redirect(array('action'=>'index'));
    }
    $this->set('something', $this->Something->findByUrl($url));
}

您可以创建beforeSave方法来处理您的网址,以获得唯一性和无法编码。

您无需使用以下路由指定www.domain.com/controller/view/latest-news

Router::connect('/*', array('controller' => 'somethings', 'action' => 'view'))

现在www.domain.com/latest-news将返回相同的页面。

答案 1 :(得分:0)

没试过这个,但我认为下面的链接可能对你有所帮助

<强> adding friendly urls to the cake application

<强> using url slugs in cakephp