简体   繁体   中英

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 the URI rewrite to the new address but it keeps the query string attached. I need to lose this. I've tried so many options and none seem to work, can anybody ofgfer some advice. I thought this 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 anybody help?

You need to add an empty query string to truncate it on the rewrite. Add a single ? 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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM