How to Clean URL in CakePHP with Route


Clean URLs are needed to help a website achieve high position in search engines. WordPress has a very good clean URLs. If you create a web application with CakePHP, the resulting URL is not too clean and does not contain elements of SEO. To that end, the CakePHP has what is called a route

Route in CakePHP needed to rewrite the URL, so it looks clean and help your website SEO process.

What I mean is: URL like this not too good, while the url like this http: //example/read/title-of-post.html much better and gives you the opportunity to to boost the ranking of your website.

The trick really simple, enough to back a route like this

Router::connect('/review/:slug', array('controller' => 'yourcontroller', 'action' => 'youraction'),array('slug' => '[a-zA-Z0-9_-]+'));

And for the link, as shown below

<?php echo $this->Html->link('Review',array('action'=>'review','controller'=>'hosts','slug'=>$item['Host']['host']));

You must add a key with the name of the slug and the value of a clean url. Therefore, it takes 1 field in a table that holds the string slug. To produce clean url slug, you can use this tool or use this script in your application

So, i hope you can improve your cakePHP app. Thanks for visiting and if this post is help you, share to your friends.