1

I have a rewrite rule that works when accessing a direct URL that doesn't have a parameter in it.

Example URL: http://mev-hongkong.com/product-category/babies-tots/

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?mev-hongkong\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^product-category/babies-tots(/.*)?$ https://mothersenvogue.com.hk/shop/all-babies-tots$1 [L,R=301,NC,NE]

However, I also have the same URLs that has a parameter that I also need to redirect to the same URL output. I tried manipulating the rewrite rule and added a %{QUERY_STRING} condition like the below rule but when I test it with the URL that has the parameter, the query strings are still not being stripped out.

Example url with parameter: http://mev-hongkong.com/product-category/babies-tots/?add_to_wishlist=8836

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?mev-hongkong\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{QUERY_STRING} ^add_to_wishlist=([^&]+) [NC]
RewriteRule ^product-category/babies-tots(/.*)?$ https://mothersenvogue.com.hk/shop/all-babies-tots$1 [L,R=301,NC,NE]

What did I miss to correctly strip off the query strings?

1 Answer 1

3

The QSD flag does exactly this:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?mev-hongkong\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^product-category/babies-tots(/.*)?$ https://mothersenvogue.com.hk/shop/all-babies-tots$1 [L,R=301,NC,NE,QSD]
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so much @Anonymous! This completely solved it!
@Weisen Great. Glad I could help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.