CakePHP offers massive support to create SEO friendly URLs on the fly. You can create SEO-friendly-urls without an ID value to refer to specific post id. It works like a charm like many other Cake MAGIC!
I'll refer to the post table.
1. Create a field called 'slug' (must be UNIQUE and NOT NULL) in the post table.
2. Download and use sluggable behavior to create post slug! Follow instructions step-by-step. It works perfectly.
3. Define routing rules in config/router.php file to display SEO friendly urls.
Router::connect(
'/posts/:slug',
array(
'controller' => 'posts',
'action' => 'view'
),
array(
'slug' => '[-a-z0-9]+',
'pass' => array('slug')
)
);
4. In posts_controller.php view() function modify query,
function view($slug = null)
{
if (empty($slug))
{
// redirect ...
}
$data = $this->Post->findBySlug($slug) ;
}
You you should be able to access urls of the form:
http://example.com/your-seo-friendly-post-url/
Hope it helps someone.
I'll refer to the post table.
1. Create a field called 'slug' (must be UNIQUE and NOT NULL) in the post table.
2. Download and use sluggable behavior to create post slug! Follow instructions step-by-step. It works perfectly.
3. Define routing rules in config/router.php file to display SEO friendly urls.
Router::connect(
'/posts/:slug',
array(
'controller' => 'posts',
'action' => 'view'
),
array(
'slug' => '[-a-z0-9]+',
'pass' => array('slug')
)
);
4. In posts_controller.php view() function modify query,
function view($slug = null)
{
if (empty($slug))
{
// redirect ...
}
$data = $this->Post->findBySlug($slug) ;
}
You you should be able to access urls of the form:
http://example.com/your-seo-friendly-post-url/
Hope it helps someone.
Do you like this Tutorial? Please link back to this article by copying one of the codes below.
URL: HTML link code: BB (forum) link code:
SEO urls in cakephp without ID is good for both users and SEO, use of variable to pass url is good for short code.
ReplyDeleteI am going to take service of CakePHP Development by xicom technologies
ReplyDeleteHello,
we provide affordable and result-oriented SEO services, please give a chance to serve you.
Thanks
Admin: E07.net