CodeIgniter Forums
Codeigniter - How do I rewrite url’s with url parameters - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Codeigniter - How do I rewrite url’s with url parameters (/showthread.php?tid=24574)



Codeigniter - How do I rewrite url’s with url parameters - El Forum - 11-13-2009

[eluser]Irshad Sheikh[/eluser]
Hi,

I need to turn URL's like /item/2 into cleaner URL's like /item/product-name-here. I'm using codeigniter. I setup rewriting in the routes.php file like this:

$route['item/(:any)'] = 'item/$1';

My question is: where do I replace the product ID "/2" 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!


Codeigniter - How do I rewrite url’s with url parameters - El Forum - 11-13-2009

[eluser]Phil Sturgeon[/eluser]
That is not possible. You should store product-name-here in the database then use that to fetch the data instead of requiring an ID.