views:

606

answers:

2

Hi,

I need to turn URL's like /catalog/products/24 into cleaner URL's like /catalog/product-name-here. I'm using codeigniter and rewrite engine is on and all setup. I also setup rewriting in the routes.php file like this:

$route['catalog/products/(:any)'] = 'catalog/view/$1';

My question is: where do I replace the product ID "/24" with "/product-name-here"? I can successfully get the param $1 and fetch the product name, but I can't figure out how to rewrite the URL with this dynamic value.

Thank you very much!

francois

+1  A: 

I'm not a codeigniter user but I smell that URL rewriting is not the best place to achieve this.

You still need to write a controller method that can identify a product using something like slug='product-name-here' instead of id=24.

Ben James
Yeah, you might be right, thanks for the answer!
Farbour
I did exactly that and it worked, thanks a lot!
Farbour
A: 

Just store the products name as a url slug into your product row in the database table. A good practice for that the url_title() method from the URL Helper.

Then you just have to search for the slug from your database in your code, rather than the id.

So this is just a hint because I don't have the time right now. But if you've got questions, ask it here, i will come back to answer it.

And sorry for my poor english! :)

Marcus André