@dudley
To enable SEO-friendly URLs in CakePHP, you need to follow these steps:
1 2 3 4 5 6 7 8 |
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php [QSA,L] </IfModule> |
The above code snippet ensures that all requests to non-existing directories or files are redirected to the index.php
file.
1
|
$routes->connect('/products/:id', ['controller' => 'Products', 'action' => 'view'], ['pass' => ['id']]); |
This will enable URLs like /products/123
instead of the default CakePHP URL structure.
1
|
echo $this->Html->link('View Product', ['controller' => 'Products', 'action' => 'view', $product['id']]); |
This will generate the appropriate SEO-friendly URL based on your routing configuration.
With these steps, you should be able to enable SEO-friendly URLs in your CakePHP application.