Search code examples
phpapache.htaccessmod-rewritepagination

how to add pagination in htaccess


hello i am looking to add pagination with htaccess i have htaccess file which rewrite my php urls from mysite.com/category.php?uid=123-slug-name to mysite.com/category/123-slug-name but i want to add pagination like this

> mysite.com/category/123-slub-name/page/1 
> mysite.com/category/123-slub-name/page/2
> mysite.com/category/123-slub-name/page/last etc

but i dont know exactly how to do this here is my htaccess file code

RewriteEngine On
RewriteRule ^category/([a-zA-Z0-9-/]+)$ category.php?id=$1
RewriteRule ^category/([a-zA-Z0-9-/]+)/$ category.php?id=$1
RewriteRule ^([a-zA-Z0-9-/]+)$ article.php?url=$1
RewriteRule ^([a-zA-Z0-9-/]+)/$ article.php?url=$1

Solution

  • You can use:

    RewriteEngine On
    RewriteRule ^category/([a-zA-Z0-9-/]+)/page/(.+)/?$ category.php?id=$1&page=$2 [NC,L]
    RewriteRule ^category/([a-zA-Z0-9-/]+)/?$ category.php?id=$1 [L]
    RewriteRule ^([a-zA-Z0-9-/]+)/?$ article.php?url=$1