I have a search engine for products on a site which I would like to give search engine friendly URLs using mod_rewrite. I use mod_rewrite frequently for simple tasks, but this one is a bit more akward.
I want this URL:
/search/cookies/betty-crocker/page1/name/
to be rewritten as
/search/products.php?q=cookies&brand=betty+crocker&page=1&order_by=name
I want to replace spaces with dashes for the ‘q’ and ‘brand’ variables in the nice URL
I want to prefix the ‘page’ variable with ‘page’ in the nice URL.
I want the ‘brand’ URL to be optional… that is, if it’s missing, then I do the same rules but without it all together so that the defaults can take over. In fact, any of them can be missing. This is the part that seems really hard to me.
Suggestions?