I've noticed that the RedirectMatch directive preserves the querystring across the redirection. That is, if http://www.mydomain.com/someurl?some=query matches the rule, then it is redirected to /whatever/other/url?some=query preserving the querystring in the new url.

How do I tell it to NOT preserve the querystring and redirect just to /whatever/other/url without any querystring?

  • I've found a partial solution which is to append a literal "?" at the end of the url to which to redirect, so the querystring is explicitly empty, and it works. But I hate to see that extra "?": can it be avoided? – matteo Mar 23 '13 at 20:29
  • Does it actually make the extra ? appear in the redirection URL that is returned in the HTTP header? – cnst Mar 23 '13 at 20:57
  • Yes definitely, or otherwise I couldn't explain how it appears in the browser's address bar :) – matteo Mar 24 '13 at 0:46

The ? at the end of the rule is the only way to explicitly delete the existing query string. From the documentation:

By default, the query string is passed through unchanged. You can, however, create URLs in the substitution string containing a query string part. Simply use a question mark inside the substitution string to indicate that the following text should be re-injected into the query string. When you want to erase an existing query string, end the substitution string with just a question mark. To combine new and old query strings, use the [QSA] flag.



There is no documentation on how to avoid query string from being appended, although the existence of the QSA option suggests that Apache might have a behaviour somewhat similar to nginx — a trailing ? will ensure that no previous query string is appended.

BTW, if this doesn't work in Apache, I wholeheartedly invite you to try nginx. Apart from having excellent performance, it also has excellent documentation and ease of configuration, and appending a ? simply makes the old string go away, and does not result in an empty question mark on the resulting redirect, either. So, it basically just works in nginx, and the whole behaviour if even officially documented, so you don't have to jump through any hoops.


If a replacement string includes the new request arguments, the previous request arguments are appended after them. If this is undesired, putting a question mark at the end of a replacement string avoids having them appended

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.