Mod_Rewrite with Query Strings

Soldato
Joined
14 Dec 2005
Posts
12,488
Location
Bath
I am confused :(.
So I started off with a basic page. Hyperlinks to the page & the browser displayed URL: http://mysite.com/category-name/page-name/
The page does not actually exist there of-course, like all of the pages on the site it is rewritten with a rule:
Code:
RewriteRule ^category-name/page-name/?$ pages/cat/page.php
All works fine. Unfortunately however the above is pretty much at the limit of what I know how to do with mod_rewrite.


I have since enhanced the page and got it to look at the query string and do different SQL queries depending on it.
With a query string stuck on the end, the URLs I'm using are now:
Code:
http://mysite.com/category-name/page-name/
http://mysite.com/category-name/page-name/?company=asus
http://mysite.com/category-name/page-name/?product=motherboard

They all work fine and my script does it's SQL stuff depending on the query string. Hurrah.

But they're ugly and I'd like to rewrite them to be pretty. Something like:
Code:
http://mysite.com/category-name/page-name/
http://mysite.com/category-name/page-name/company/asus/
http://mysite.com/category-name/page-name/product/motherboard/

(Later on I'll be working out what to do with multiple parameters, but getting it working with just one parameter is more than I can do now!).

I've had some attempts based on googling, but it's not getting anywhere. Probably my regex letting me down!

Any help appreciated! I wasn't expecting this to be the bit that stumped me!
 
Back
Top Bottom