I am having trouble with uri segments in codeigniter I am looking to develop products and product details so I created a controller for it and passed a parameter of product name to show product name in the url so my url will become like this 

> 
> localhost/project\_name/products/product\_name 
> 
> 
> 

and this part is working fine for me but I am confused about what If I would like to display as products category and product name like I am trying to make my url like this 

> 
> localhost/project\_name/products/category\_name /product\_name 
> 
> 
> 

so how I will do this now when I pass in category name it shows me 404 not found The page you requested was not found. as some times direct product will be shown and sometimes if users go through the product details via category so the category name will passed in the url and also how this segements work ? I am having big confusion about this

Here is my controller for products 

```
public function products($product_name) {
        if($this->uri->segment(3)) {
            $category = ucwords(str_replace('-', " ", $product_name));
            $product  = ucwords(str_replace('-', " ", $this->uri->segment(3)));
        } else {
            $product  = ucwords(str_replace('-', " ", $product_name));
        }

        $page_data = $this->get_data->get_Data($product, 'name', 'products');
        $data['title'] = 'Products - ' . $page_data->row()->name;
        $data['body_class'] = 'poductsdetails';

        $this->load->view('includes/header.php', $data);
        $this->load->view('templates/navigation.php');

        $data['content'] = array(
                'name'        => $page_data->row()->name,
                'price'       => $page_data->row()->price,
                'description' => $page_data->row()->description,
                'picture'     => $page_data->row()->picture,
                'category'    => $page_data->row()->category,
            );

        $this->load->view('products/details', $data);
        $this->load->view('templates/footer-form.php');
        $this->load->view('includes/footer.php');
    }

```

And here is my routes I have created

```
$route['default_controller'] = 'home';
$route['admin']              = 'admin/index';
$route['admin/([a-z])']      = 'admin/$1';
$route['products/(:any)']    = 'home/products/$1';
$route['products/(:any)']    = 'home/products/$1/$2';
$route['products/(:any)']    = 'home/products/$1/$2/$3';
$route['(:any)']             = 'home/page/$1';
$route['(:any)']             = 'home/page/$1/$2';

```