PDA

View Full Version : Need help with .htaccess with query string


basahkuyup
10-16-2006, 03:56 AM
I have this in my .htaccess:

RewriteRule ^products/([0-9]+).html$ productlist.php?catid=$1 [L]

I have a page productlist.php that lists all products for a particular category (catid). The rewriterule works fine if I have only 1 page of products. Example:

products/8.html will be rewritten to productlist.php?catid=8

The problem is when I have to go to second page of a particular product category, it will keep showing the first page. The link to second page is the following:

products/8.html?start=2&pageno=2

I expect the rewriterule will rewrite it to

productlist.php?catid=8&start=2&pageno=2

but it didn't happen.

Anyone have any ideas?

vinyl-junkie
10-16-2006, 05:36 AM
Have a look at Search Engine-Friendly URLs (http://www.sitepoint.com/article/search-engine-friendly-urls) for several methods with which you can incorporate multiple variables into your URLs. Alternatively, you could have pages with the category name in the page, something like this:

RewriteRule ^OneCategory([0-9]+)\.php /OneCategory.php?page=$1 [L]
That way, the page number is the only variable in the URL.

basahkuyup
10-17-2006, 09:15 AM
Thanks vinyl-junkie. I went to the site but could not find the help that I need.
Anyway I have found a way to this. I add QSA in the rewriterule as the following:

RewriteRule ^products/([0-9]+).html$ productlist.php?catid=$1 [L,QSA]

and it works.

vinyl-junkie
10-17-2006, 01:50 PM
RewriteRule ^products/([0-9]+).html$ productlist.php?catid=$1 [L,QSA]
Excellent! This is something that I wasn't aware of. Thanks! :thumbsup: