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?
The
?
at the end of the rule is the only way to explicitly delete the existing query string. From the documentation:http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html
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 tonginx
— 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.http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#rewrite