URL重写分页

I have a Problem . Pagination with Rewrite Url .

My Current Link (Worked) here

localhost/nhagiagoc/sell-book-for-5

When I clicked to next page , i get this link .

localhost/nhagiagoc/sell-book-for-5_page-1

At this time , I keep clicking on paging link and I will get this link .

localhost(dot)com/nhagiagoc/sell-book-for-5_page-1_page-2

and so i get multi link like this

localhost/nhagiagoc/sell-book-for-5_page-1_page-2_page-3

localhost/nhagiagoc/sell-book-for-5_page-1_page-2_page-3_page-4

localhost/nhagiagoc/sell-book-for-5_page-1_page-2_page-3_page-4_page-5

So , How to fix that problem ? I use $_SERVER['REQUEST_URI'] get worked link , if I used $_SERVER['PHP_SELF'] , i got php link ( not rewrite link ) . ( ex : localhost/nhagiagoc/book.php?id=135 ) .

I guess the whole problem is about using $_SERVER['REQUEST_URI'] when you are creating next page link.

You are probably using something like this actually :

$actualPage = $_SERVER['REQUEST_URI'];
echo '<a href="'.$actualPage.'_page-'.++$_GET['page'].'">Next page</a>';

The problem here is that $_SERVER['REQUEST_URI'] already contains /sell-book-for-5_page-1, so adding _page-'.++$_GET['page'] make those url. Instead of using $_SERVER['REQUEST_URI'], you need to use URL without pagination, then add it

Exemple :

$pagination = (isset($_GET['page']) && $_GET['page'] > 0)?$_GET['page']:1;
$actualPage = '/sell-book-for-'.$idFromDB; //Like you already did
echo '<a href="'.$actualPage.'_page-'.($pagination+1).'">Next page</a>';

You'll need to update this to work for you, hope you still got the point.