Zhianc
Zhianc

Reputation: 1451

mod_rewrite on optional Get parameters

RewriteRule ^category/([0-9]{1,2})/?$  /category.php?id=$1

^That rewrites to: /category/<number>/

What should i add for the OPTIONAL page number? category.php?id=2&page=2. Means /category/<number>/ is equal to /category/<number>/page-1/

Upvotes: 0

Views: 256

Answers (1)

Book Of Zeus
Book Of Zeus

Reputation: 49887

In order to use pagination you will have to add an extra param in the URL. If you want /category/<number>/ to go to a specific ID and /category/<number>/ to go to a specific page you will have a conflict.

What you have to do is this:

RewriteRule ^category/([0-9]+)/?$  /category.php?id=$1&page=1 [NC,L]
RewriteRule ^category/([0-9]+)/page\-([0-9]+)/?$  /category.php?id=$1&page=$2 [NC,L]

This means if you use /category/<number>/ it goes to a specific ID and loads the page #1 and then you can load a specific page using /category/<number>/<page>/.

Upvotes: 2

Related Questions