Sandeep Tawaniya
Sandeep Tawaniya

Reputation: 717

Paging URL rewriting not working in php using .htaccess

I am using this rule in .htaccess :-

RewriteRule ^online-sale on-sale.php
RewriteRule ^online-sale/page-([0-9]+)$ on-sales.php?page=$1

First rule is working fine. for eg. if i call http://www.sitename/online-sale than page is opening successfully. When i am calling http://www.sitename/online-sale/page-2 than page is opening fine, but I can't access $_REQUEST["page"] value on this page.

Can anyone suggest me what is the problem? Is it possible or not?

Thanks in advance.

Upvotes: 1

Views: 122

Answers (1)

anubhava
anubhava

Reputation: 785276

You need to use anchor $ in first rule to avoid matching for paging URL as well:

RewriteRule ^online-sale/?$ on-sale.php [L]
RewriteRule ^online-sale/page-([0-9]+)/?$ on-sale.php?page=$1 [L,QSA]

It is also advisable to use L and QSA flags.

QSA (Query String Append) flag preserves existing query parameters while adding a new one.

Upvotes: 1

Related Questions