How to remove page from pagination URL
<p>I have written a SEO-friendly pagination function which is working fine. However, my current url looks like this:</p>

<p><strong>1.</strong> <code>localhost/test/tastepage.php/test/testpage/page/123</code></p>

<p>But what i want to accomplish is:</p>

<p><strong>2.</strong> <code>localhost/test/testpage.php/page/123</code> or <code>localhost/test/testpage.php/123</code></p>

<p>When I go to the url bar and edit my url to like <strong>2</strong> It is working fine. But i want to know, why does my URL look like <strong>1</strong> whenever I load the page for the first time?</p>

<p>Here is what I have in my tastpage.php file:</p>

<pre><code>$page=1;//set page number to 1 as default
$sitepath=explode('/',parse_url($_SERVER['REQUEST_URI'],PHP_URL_PATH));//removing slashes from the url and slicing up the url into an array
if(is_array($sitepath)&amp;&amp; !empty($sitepath)){
    if($keys=array_search('page',$sitepath)){;
    print_r($keys);
    $page=(int)$sitepath[$keys+1];
    }
}
function paginate($page,$display,$total){
$sitepath=parse_url($_SERVER['REQUEST_URI'],PHP_URL_PATH);
  if($sitepath!='/'){
      $sitepath=rtrim($sitepath,'/');
      if(stristr($sitepath,'page/')){
          $sitepath=rtrim($sitepath,'0..9');
          $query='';
      }
      else {
         $query=$sitepath .'/page/';
     }
  }
      else {
        $query = 'page/';
    }
$pages=ceil($total/$display );

$first='&lt;a href="'.$sitepath.$query.'1"&gt;First&lt;/a&gt;';
$last='&lt;a href="'.$sitepath.$query.$pages.'"&gt;Last&lt;/a&gt;';
$next='&lt;li&gt;&lt;a href="'.$sitepath. $query . ($page + 1) . '"&gt;»&lt;/a&gt;&lt;/li&gt;';
$preview='&lt;li&gt;&lt;a href="'.$sitepath.$query.($page-1).'"&gt;«&lt;/a&gt;&lt;/li&gt;';
$numbers="";
for ($i=max(1,$page-5);$i&lt;=min($page+1,$pages);$i++)
{
    if($i==$page){
    $numbers.='&lt;li&gt;&lt;a class="active" href="'.$sitepath.$query.$i.'"&gt;'.$i.'&lt;/a&gt;&lt;/li&gt;';
    }
    else {
        $numbers.='&lt;li&gt;&lt;a href="'.$sitepath.$query.$i.'"&gt;'.$i.'&lt;/a&gt;&lt;/span&gt;&lt;/li&gt;';
    }
}
   if($page&gt;1){
     echo $preview;
   }

 echo  $numbers; 

   if($page&lt;$pages){
      echo  $next;
   }
    };

$limit = 10;
//count how many rows 
$total = $conn-&gt;query("SELECT COUNT(*) FROM pagi")-&gt;fetchColumn();

if ($total &gt; 0) {
    $start = $limit * $page - $limit;
    $sql = $conn-&gt;prepare("SELECT * FROM pagi ORDER BY pg_id LIMIT :start, :limit");
    $sql-&gt;bindValue(':start', $start, PDO::PARAM_INT);
    $sql-&gt;bindValue(':limit', $limit, PDO::PARAM_INT);
    $sql-&gt;execute();
    if ($sql-&gt;rowCount() &gt; 0) {
        while ($result = $sql-&gt;fetch(PDO::FETCH_ASSOC)) {
            echo $result['pg_name'],"&lt;br /&gt;";
        }
    }
} else {
    echo "no result to fetch";
}
 ?&gt;
</code></pre>