Even when GET
and named
parameters can be useful in most situations, we may need to further optimize our application URLs for better search engine rankings.
Fortunately, CakePHP provides us with route elements, a solution that maintains the flexibility of GET
and named parameters, and improves the way intra-application URLs are built.
We need some sample data to work with. Follow the Getting ready section of the recipe Using GET and named parameters.
1. We want our article URLs to be further optimized for search engines, so we start by creating a new route. Edit your
app/config/routes.php
file and add the following route at the end of the file:Router::connect('/article/:category/:id-:title', array('controller' => 'articles', 'action' => 'view'), array( 'pass' => array('id'), 'id' => '\d+', 'category' => '[^-]+', 'title' => '[^-]+' ) );
2. As our route defines three elements (
id
,category
, andtitle
), we need to modify...