2

I need to turn URL's such as the following:

/catalog/products/24

into cleaner URL's such as the following:

/catalog/product-name-here

I'm using CodeIgniter, and rewrite engine is on and setup. I also setup rewriting in the routes.php file as follows:

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

Question: Where do I replace the product ID /24 with /product-name-here? I can successfully get the parameter $1, and fetch the product name. I can't seem to figure out how to rewrite the URL with this dynamic value though. Thanks in advance!

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

Just store the products name as a URL slug into your product row in the database table. 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! :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.