Question

i have codeigniter project. i am show the product page using router.php for the url change. Here i am facing some problems. the router code is here

Url                                 router.php code   
www.sitename.com/products/page/2 -> $route['products/page/(:num)'] = "products";
www.sitename.com/products/product-name -> $route['products/(:any)'] = "products/detail/$1";
www.sitename.com/products/product-categories -> $route['products/(:any)/(:num)'] = "products/selbygrp/$2";

the above code working fine for particular product detail view. But logically i have issues

problem: if i go to pagination links the router go to second route code . and also if select particular product group categories list it will go to second route code . what ever i gave it will go to second route line.

i know the reason for this. if products/ after anything it will take second route. but i don't need like this. the following urls i want

www.sitename.com/products/productname -> for product detailview
www.sitename.com/products/product-categories -> list product categories wise 
www.sitename.com/products/page/number -> show product list with pagenation 

i am stuck with this, if any possible to do with htaccess for this, give me the guidance thanks advance

Was it helpful?

Solution 3

thanks to all of you gave me a good answer. finally i found the answer. the answer is here when the url go to product categories , i created a controller for it and then i routed like this

url -> www.sitename.com/productgroup/groupname

route -> $route['productgroup/(:any)'] = "productgroup/selgrp/$1";

the above route is redirect to productgroup controller when i am hit the product categories. so the pagination problem also solved.

again i say thanks to every to gave me good answer.

OTHER TIPS

To solve the problem, just move

$route['products/(:any)/(:num)'] = "products/selbygrp/$2";

above

$route['products/(:any)'] = "products/detail/$1";

If I am understanding you correctly, your link breaks after the second page of the pagination. When it sticks this /2 or any other number in the url.

This is what I have to fix that issue, I was doing the same thing last night.

In my pagination base url I switched it to the new url

$config["base_url"] = base_url()."/products;

and then in my routes I added another route to accommodate for the pagination.

$route['products/(:any)'] = "products/page/$1";
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top