2

I heve the following rule:

RewriteRule ^/shop$ https://www.example.com/category

the rule is working as expected with one exception: if in url there are parameter following the shop path, for example:

https://www.example.com/shop?order=name+asc. I would not match this uri, but with the above sintax the rule is triggered. how can I skip it?

  • Note that without any flags the above RewriteRule directive will result in a 302 temporary redirect and processing will continue through the file. Ideally you should be explicit about the redirect and include the R flag and use the L flag to prevent further processing. – MrWhite Aug 25 '18 at 14:02
1

You could add a condition to ensure that the query string is blank:

RewriteCond %{QUERY_STRING} "^$"
RewriteRule ^/shop$ https://www.example.com/category

By default the query string is not considered by rewrite rules. They only match the URL path. You have to add conditions if you need to pay attention to the query string.

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.