开发者

How to use SEO urls in CakePHP without the ID?

开发者 https://www.devze.com 2023-01-07 11:20 出处:网络
Is there a simple way to route my URLs without showing the ID in the URL. For example i have:开发者_JAVA技巧

Is there a simple way to route my URLs without showing the ID in the URL. For example i have:

开发者_JAVA技巧

www.mywebsite.com/id-article-title.html and i want only www.mywebsite.com/article-title.html

Regards


Add a url column to your db table. Then you can do findByUrl(). As noted above it's well documented.

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

You can create beforeSave methods to process your urls for uniqueness an uuencoding.

You can eliminate the need to specify www.domain.com/controller/view/latest-news using routes like:

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

Now www.domain.com/latest-news will return the same page.


Haven't tried this one but I think the link below may help you somewhat

adding friendly urls to the cake application

using url slugs in cakephp

0

精彩评论

暂无评论...
验证码 换一张
取 消