Mohammad Masoudian
Mohammad Masoudian

Reputation: 3491

Get Page Number from Rewrited URL

i wrote this Rewrite Rule :

RewriteRule ^(products)/(page[0-9]+)?/?$ index.php?action=$1&page=$2 [L]

in following url this will happen :

rewrited url : http://www.silvergroup.ir/products/page2

what actually is : http://www.silvergroup.ir/index.php?action=products&page=page2

but i need the number of page only and whole of page variable is optional, this means following url is allowed :

http://www.silvergroup.ir/products

thank you

Upvotes: 1

Views: 82

Answers (1)

anubhava
anubhava

Reputation: 785146

Use this rule instead:

RewriteRule ^(products)(?:/page([0-9]+))?/?$ index.php?action=$1&page=$2 [L,NC,QSA]

This will forward

  • /products to /index.php?action=$1&page=
  • /products/ to /index.php?action=$1&page=
  • /products/page2 to /index.php?action=$1&page=2

Upvotes: 2

Related Questions