Link to home
Start Free TrialLog in
Avatar of Crazy Horse
Crazy HorseFlag for South Africa

asked on

pretty urls product pagination

I can't get the rewrite rule correct in order to create pretty url's with pagination.

This is my current rule for listing products within a category:

RewriteRule ^product-category/([a-zA-Z-]+)$ category.php?slug=$1 [NC,L]

Open in new window

The result is something like mysite.com/product-category/shirts

I want the pagination url after clicking on "2" for example, to be

mysite.com/product-category/shirts/page/2
I tried this but it doesn't work and just looks wrong:

RewriteRule ^product-category/([a-zA-Z-]+) category.php?slug=$1/page/([a-zA-Z-]+)$ pagination?=$1 [NC,L]

Open in new window

I get an internal server error.
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Add QSA to your rule

RewriteRule ^product-category/([a-zA-Z-]+)$ category.php?slug=$1 [NC,L, QSA]

Open in new window


That will pass any query string parameters to the original link to the rewritten one
Avatar of Crazy Horse

ASKER

Thanks Julian. I tried that but I get a "not found" error. Perhaps the issue is now in my PHP?

for($page = 1; $page <= $number_of_pages; $page++) {
				
	echo "<li><a href='product-category/$page_url/page/$page'>{$page}</a></li>";
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial