简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM