CakePHP friendly seo url

Viewed 3954

I want to make my url seo friendly. www.example.com/posts/view/1 change for www.example.pl/:slug-:id. Everything works fine, but probably I'm doing something wrong with routing, because when after clicking the urls in paginator, the url is correct, it looks like www.example.pl/:slug-:id , but it appears an error

"The requested address 'www.example.pl/:slug-:id' was not found on this server."

I don't know what's wrong. Here's my code:

Router::connect(
    '/:slug-:id',
    array(
        'controller' => 'posts', 
        'action' => 'view'
    ),
    array(
        'pass' => array('slug' , 'id'),
        'id' => '[0-9]+'
    )
);

in paginator view:

echo $this->Html->link($ad['Post']['title'], array(
    'controller' => 'posts',
    'action' => 'view',
    'slug' => Inflector::slug($post['Post']['title'],'-'),
    'id'=>$post['Post']['id'])
);

I solved the problem.

5 Answers
Related