Pagination with permalink (SEO friendly)

2 posts by 2 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: March 5, 2015   (RSS)

By Daryl - March 5, 2015

Hi Jesus,

You can use .htaccess to rewrite the pagination URL.

For example:
We will rewrite www.domain.com/section-name/?page=2 to www.domain.com/section-name/page-2

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule   ^section-name/page-([0-9]+)/?$   section-name/?page=$1 [QSA]

And then on your pagination links, replace the default ?page=1, ?page=2 and so on with /page-1, /page-2 and so on.

How it works:
The "([0-9]+)" part of the htaccess code, which will contains the page number, is passed over to "$1"
This means that your $_REQUEST['page'] will have a value equals to whatever number is in the "([0-9]+)".

If you're using permalink plugin, the rewrite code should come before the permalink htaccess dispatcher code.

Cheers,

Daryl Maximo
PHP Programmer - interactivetools.com