Htaccess rewrite to remove query string
I need to rewrite the following:
http://www.mystuff.com/drinks/category/beer?page=1
to
https://www.mystuff.com/food-drink/beer/ale
No matter what I try to rewrite the URI to a new address, but it does support the query string. I need to lose it. I have tried so many options and none seem to work, can anyone give some advice. I thought it would do it, but no:
RewriteCond %{QUERY_STRING} (.*)(?:^|&)page=(?:[^&]*)((?:&|$).*)
RewriteCond %1%2 (^|&)([^&].*|$)
RewriteRule ^(/drinks/category/beer)$ https://www.mystuff.com/food-drink/beer/ale [R=301, L]
Can anyone please help?
0
source to share
1 answer
You need to add an empty query string to truncate it on rewriting. Add one end ?
to the end of the rewrite:
RewriteCond %{QUERY_STRING} (.*)(?:^|&)page=(?:[^&]*)((?:&|$).*)
RewriteCond %1%2 (^|&)([^&].*|$)
RewriteRule ^(/drinks/category/beer)$ https://www.mystuff.com/food-drink/beer/ale? [R=301, L]
+1
source to share