Reputation: 307
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
Upvotes: 1
Views: 2836
Reputation: 71
This is my example here.
I have more sites and sites have more pages. And every page has an owner. But first. I redirect all http request to https
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
# From GET to Pretty
RewriteCond %{THE_REQUEST} /?sitename=([^\s&]+)&page=([^\s&]+) [NC]
RewriteRule ^ /%1/page-%2? [R=301,L,NE]
# From GET to Pretty
RewriteCond %{THE_REQUEST} /?sitename=([^\s&]+)&owner=([^\s&]+) [NC]
RewriteRule ^ /%1/owner-%2? [R=301,L,NE]
# From GET to Pretty
RewriteCond %{THE_REQUEST} /?sitename=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=301,L,NE]
# Pretty req index.php
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
RewriteRule ^ %1 [R=301,L]
RewriteRule ^([^/.]*)$ /index.php?sitename=$1 [NC,L]
RewriteRule ^([^/.]*)/page-([^/.]*)$ /index.php?sitename=$1&page=$2 [NC,L,QSA]
RewriteRule ^([^/.]*)/owner-([^/.]*)$ /index.php?sitename=$1&owner=$2 [NC,L,QSA]
Upvotes: 0
Reputation: 18671
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
Upvotes: 6