开发者

Get htaccess to add value as GET variable when redirecting

开发者 https://www.devze.com 2023-01-13 13:32 出处:网络
Simply put, what I want to achieve is this, www.example.com/show-products/food should be redirected to

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&开发者_StackOverflow社区amp;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}


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]
0

精彩评论

暂无评论...
验证码 换一张
取 消