title: How to set up pagination url to be able to use url rewriting using htaccess?
body: <p>My current pagination code looks like this  </p>
  
  <pre><code>//what page are we currently on
  if(!isset($_GET['page'])){
      $page=1;
      }
      else {
          $page=(int)$_GET['page'];
      }
  //select how many records to show per page
  $limit=10;
  //count how many rows 
  $total=$conn-&gt;query("SELECT COUNT(*) FROM pagi")-&gt;fetchColumn();
  //how many pages will be there
  $pages=ceil($total/$limit);
  if($page&lt;1){
      $page=1;//forcing page to be 1 if it is less then 1
      }   
  else if($page&gt;$pages){
      $page=$pages;
      }
  //calculate the offset 
  $offset=($page-1)*$limit;
  //fetch the result from database
  $sql=$conn-&gt;prepare("SELECT * FROM pagi ORDER BY pg_id LIMIT {$limit} OFFSET {$offset}");
  $sql-&gt;execute();
  if($sql-&gt;rowCount()&gt;0){
  while($result=$sql-&gt;fetch(PDO::FETCH_ASSOC)){;
  echo $result['pg_name'],"&lt;br /&gt;";   
  }
  echo "&lt;hr&gt;";
  }else {
      echo "no result to fetch";
  }   
  
  $prev=$page-1;
  $next=$page+1;
  $previous="";
  $nextr="";
  if($page&gt;1){
  $previous='&lt;li&gt;&lt;a href="?page='.$prev.'"&gt;«&lt;/a&gt;&lt;/span&gt;';
  }
  //for($i=1;$i&lt;=$pages;$i++){
  //  echo'&lt;a href="?page='.$i.'"&gt;'.$i.'&lt;/a&gt;';
  //  }
  if($page&lt;$pages){
  $nextr='&lt;li&gt;&lt;a href="?page='.$next.'"&gt;»&lt;/a&gt;&lt;/span&gt;';
  }
  $numbers="";
  for($i = max(1, $page - 5); $i &lt;= min($page + 5, $pages); $i++){
      if($i==$page){
      $numbers.='&lt;li&gt;&lt;a class="active" href="?page='.$i.'"&gt;'.$i.'&lt;/a&gt;&lt;/span&gt;&lt;/li&gt;';
      }
      else {
          $numbers.='&lt;li&gt;&lt;a href="?page='.$i.'"&gt;'.$i.'&lt;/a&gt;&lt;/span&gt;&lt;/li&gt;';
      }
      }
  </code></pre>
  
  <p><strong>And my current url look like this</strong> :- <code>localhost/test/pagi.php?page=1</code></p>
  
  <p><code>I want it to be</code> <code>localhost/test/pagi.php/page/1</code></p>
  
  <p>I have this following in my <code>.htaccess</code></p>
  
  <p><code>RewriteEngine on
   RewriteRule ^page/([a-zA-Z0-9-/]+)$ pagi.php?page=$1</code></p>
  
  <p>How can i change my pagination to work with above rewrite rule or maybe another rules; I want to be able to achieve when a user click on next it should redirect 
  them to <code>pagi.php/page/123</code> not to <code>pagi.php?page=1</code>.I am pretty new to php and cant figure out a way to do this.Any help would be great</p>