title: Codeigniter Pagination first page is always current page
body: <p>I am pulling my hair out on this one. I am using CodeIgniters pagination library and right now it is always stuck on page 1 as the current page. I have checked a bunch of StackOverflow questions and I don't have the same problem as anyone else. </p>
  
  <p>Here is my url structure</p>
  
  <pre><code>website.com/leaders/page/[page_number]
  </code></pre>
  
  <p>Here is the pagination code in my controller</p>
  
  <pre><code>    $this-&gt;load-&gt;library('pagination');
  
      $config['per_page'] = $query_config['limit'];
      $config['base_url'] = base_url() . 'leaders/page/';
      $config['total_rows'] = 2000; // I actually use a function for this number
      $config['full_tag_open'] = '&lt;div id="paginate"&gt;';
      $config['full_tag_close'] = '&lt;/div&gt;';
      $config['first_link'] = '&amp;laquo; First';
      $config['last_link'] = 'Last &amp;raquo;';
      $config['use_page_numbers'] = true;
      $config['uri_segment'] = 3;
  
      $this-&gt;pagination-&gt;initialize($config);
  </code></pre>
  
  <p>When I echo the pagination in the view it looks like it works. The urls on each link is correct and everything looks fine. The last link shows the last page url and the current page is 1. However when I click on page 2 or any other page from the pagination, it still shows page 1 as the current page even though the url is as follows</p>
  
  <pre><code>website.com/leaders/page/2
  </code></pre>
  
  <p>I used the <code>$this-&gt;uri-&gt;segment(3)</code> to grab the page number for my database queries so the page number is in the right segment. Just to double check I set the <code>$config['uri_segment']</code> values to 1,2,3,4,5,6 just to make sure.</p>
  
  <p><em>I found out the problem while writing this but I am still confused</em></p>
  
  <p>Then I thought maybe there is something going on with the url itself as I have a route directing it to the index method in the controller. Here is what my routes file looks like</p>
  
  <p><strong>routes.php</strong></p>
  
  <pre><code>$route['leaders/page/(:num)'] = 'leaders/index';
  $route['leaders/page'] = 'leaders/index';
  </code></pre>
  
  <p>Then I tried setting the base_url for the pagination config to send it to the index directly like so:</p>
  
  <pre><code>$config['base_url'] = base_url . 'leaders/index';
  </code></pre>
  
  <p>Now it seems to be working properly. But how do I make it so that it works with the url structure I had before? I just think it looks nicer and I don't really need a method in the controller for this. Is there something conflicting in my routes.php file?</p>
  
  <p>Thanks</p>