在CodeIgniter中路由

I am creating e-commerce website in CodeIgniter and I Have to prepare SEO friendly URL.

Currently My URL is:-

abc.com/product/product_list/1/categoryName

  • product is my controller
  • product_list is my function name
  • 1 = category id
  • categoryName is my category Name

And I have to make like this:-

abc.com/categoryName

I have to remove controller name as well as function name and one uri segment i.e., category id and show only category name.

How can I do this? Is this possible using .htaccess file?

You can use route as:

$route["(:any)"] = "product/product_list/$1";

But issue is that it will hurt your other controllers like if you have page like

abc.com/contactus

It will call the product/product_list/. I suggest you to use route as:

$route["category/(:any)"] = "product/product_list/$1";

You can use URL like:

abc.com/category/yourCatName

And get category name in controller by using CI Segments.

CI Routes