There are external links pointing to my site (that I have no control over) which contain bad query strings. Here is an example:
http://www.example.com/page/&query=string
The above results in a 404 page on my site. Because “http://www.example.com/page/” exists on my site, I want to use a .htaccess file to remove any bad query strings so the user can get to the correct content.
So I want this rewrite or redirect:
http://www.example.com/page/&query=string -> http://www.example.com/page/
Any and all help is appreciated!
The following should do as you said issuing a 301 redirect to the requesting browser.
However you just want to serve the right content you can avoid the 301 redirect with this:
It will remove the QUERY_STRING entirely so be aware.
If you wanted to rewrite some different query strings but not all for /page/
All RewriteRules assume that you have the “RewriteEngine On” somewhere, it is possible likely that your host has this done. It will also require the mod_rewrite module in Apache which I assume is in use based on the .htaccess request.
http://httpd.apache.org/docs/2.4/mod/mod_rewrite.html
That all said this seems very unnecessary as a page will ignore the arguments if it does not need them, unless of course this is being passed to a script in which case you should be able to handle this in the code, but perhaps you have a framework that is causing issues.
This is a great book on the subject:
Pro Apache
See pages 277-299