views:

17

answers:

1

Hey,

Simply put, what I want to achieve is this,

www.example.com/show-products/food should be redirected to www.example.com/show_products.php?cat_id=1

or www.example.com/show-products/clothes should be redirected to www.example.com/show_products.php?cat_id=8

But, I want htaccess to send the GET variables from the URL to the script as well. So www.example.com/show-products/food?sort=price&sort_order=asc should be redirected to www.example.com/show_products.php?cat_id=1?sort=price&sort_order=asc&cat_id=1

I know the way I formulated the question is not the best but hopefully you can make sense of it.

Thanks.


I found the answer, it's easier than I expected, the condition is:

RewriteRule ^food(/)?$ show_products.php?cat_id=1&%{QUERY_STRING}
+2  A: 

The way that you've done it is fine, but keep in mind that you can also use the QSA flag. This automatically appends the existing query string to the query string which you generate with your rewrite, handling the concatenation for you automatically.

This would look like the following:

RewriteRule ^food(/)?$ show_products.php?cat_id=1 [QSA]
Tim Stone