CodeIgniter - How to rewrite URL with URL parameters
I need to include a url like:
/catalog/products/24
to a cleaner url like:
/catalog/product-name-here
I am using CodeIgniter, and the engine overwrites is enabled and configured. I also set up the rewriting in the file routes.php
like this:
$route['catalog/products/(:any)'] = 'catalog/view/$1';
Question . Where to replace the product ID /24
on /product-name-here
? I can successfully get the parameter $1
and get the product name. I can't seem to figure out how to rewrite the url with this dynamic value. Thanks in advance!
source to share
Just store the product name as a URL in your product string in the database table. A good practice for this is url_title()
from URL Helper .
Then you just need to look for the slug from your database in your code, not the ID.
So this is just a hint because I don't have time right now. But if you have any questions, ask them here, I'll be back to answer them.
And sorry for my bad english! :)