title: Codeigniter: Routing and URI Segments
body: <p>I'm having an issue with routing in codeigniter. </p>
  
  <p>Lets say I have a controller named Pages, with a method named product that does the following: </p>
  
  <pre><code>public function product() {
      $this-&gt;load-&gt;model('pages_model');
      $productid = $this-&gt;uri-&gt;segment(3);
  
      $data['product'] = $this-&gt;pages_model-&gt;getProduct($productid);
      // ...load view, etc.
  }
  </code></pre>
  
  <p>To access a particular product, my url will be www.example.com/pages/product/ID. </p>
  
  <p>I want to setup a custom route so I can access the product by going to www.example.com/name-of-product.</p>
  
  <p>However, putting </p>
  
  <pre><code>$route['name-of-product'] = 'pages/product/ID'; 
  </code></pre>
  
  <p>does not work. It will load the product view, but the product data will not be loaded. If I say </p>
  
  <pre><code>$route['name-of-product/:any/ID'] = 'pages/product/ID';
  </code></pre>
  
  <p>it works as it should, but I would rather not have the two additional segments at the end of the url.  </p>