I would like to remove all query strings including parameters and values from URLs with htaccess rules.
Here are a few URLs with query strings as examples which are needed to be removed from the end of URLs.
https://example.com/other-category-slug/page/15/?orderby=price-desc&add_to_wishlist=342
https://example.com/page/62/?option=com_content&view=article&id=91&Itemid=2
https://example.com/page/30/?start=72
https://example.com/other-category-slug/page/12/?add_to_wishlist=9486
https://example.com/other-category-slug/page/15/?add_to_wishlist=9486
https://example.com/other-category-slug/page/4/?orderby=price-desc&add_to_wishlist=332
https://example.com/other-category-slug/page/15/?orderby=price-desc&add_to_wishlist=5736
https://example.com/other- category-slug/page/7/?orderby=popularity
https://example.com/other-category-slug/page/15/?add_to_wishlist=350
https://example.com/category-slug/page/19/?orderby=price-desc
https://example.com/category-slug/page/3/?orderby=date
https://example.com/page/2/?post_type=map
https://example.com/category-slug/page/2/?PageSpeed=noscript
https://example.com/category/page/6/?orderby=menu_order
https://example.com/page/50/?Itemid=wzshaxrogq
https://example.com/category-slug/page/1/?orderby=price&add_to_wishlist=12953
https://example.com/category-slug/this-is-product-slug/?PageSpeed=noscript
https://example.com/category-slug/?add_to_wishlist=15153
https://example.com/page/24/?op
https://example.com/page/68/?iact=hc&vpx=262&vpy=212&dur=2871&hovh=259&hovw=194&tx=104&ty=131&ei=KJ05TtKZOoi8rAfM2ZmPBQ&page=1&tbnh=129&tbnw=97&start=0&ndsp=35&ved=1t%3A429%2Cr%3A9%2Cs%3A0&doing_wp_cron=1466467271.7778379917144775390625
I need clean URLs like these without query strings and parameters.category-slug and product-slug are just examples. I believe i need 5 rules.
https://example.com/category-slug/product-slug/
https://example.com/category-slug/page/15/
https://example.com/category-slug/
https://example.com/page/62/
https://example.com/
Here are a few query strings which I want to keep.
https://example.com/?attachment_id=123
https://example.com/?p=123
https://example.com/page/12/?fbclid=PAAaaK8eCN
https://example.com/your-shopping-cart/?remove_item=22c1acb3539e1aeba2
https://example.com/category-slug/this-is-product-slug/?add-to-cart=29030
https://example.com/?s=%7Bsearch_term_string%7D
Here is my code which is not working. In fact I don't understand the Regex in them.
RewriteEngine On
RewriteRule ^(page/[0-9]+)/.+$ /$1? [L,NC,R=301]
RewriteCond %{QUERY_STRING} ^option=.+$ [NC,OR]
RewriteCond %{QUERY_STRING} ^[^=]+$
RewriteRule ^$ /? [L,NC,R=301]
Thanks in advance
remove_item=is shown in removals as well as in keepsadd_to_wishlistlook as if they are potentially destructive. Redirecting would be an attempt at "fixing" this. Long term they would need to make sure they are setting the correct canonical meta tag.