【问题标题】:How to use SEO urls in CakePHP without the ID?如何在没有 ID 的情况下在 CakePHP 中使用 SEO url?
【发布时间】:2011-03-15 18:24:50
【问题描述】:

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

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

问候

【问题讨论】:

    标签: cakephp seo routes url


    【解决方案1】:

    在您的数据库表中添加一个 url 列。然后你可以做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 方法来处理您的 url 以实现 uuencoding 的唯一性。

    您可以消除指定 www.domain.com/controller/view/latest-news 的需要,使用如下路由:

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

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

    【讨论】:

      【解决方案2】:

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

      adding friendly urls to the cake application

      using url slugs in cakephp

      【讨论】:

        猜你喜欢
        • 2014-05-11
        • 2013-06-15
        • 2015-06-16
        • 2011-01-23
        • 2014-02-06
        • 1970-01-01
        • 2014-07-20
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多