Someone is creating erroneous links by adding a question mark and random characters to random pages on my website in the following format:
- www.mydomain.com/?57237933 (only numbers)
- www.mydomain.com/folder1/?709d0c24941 (with letters)
- www.mydomain.com/folder1/page-name/?20?9h572 (double question mark)
I have found a block rule for robots.txt but need a stronger htaccess solution. I am looking for a htaccess rewrite rule that can remove the ?
and everything following it from any URLs, redirecting the visitor to the original URL.
I've found solutions to remove, for example, ?id=123
but when id=
isn't there I haven't found a solution.
I cannot test it right now, but I think this would be the solution to your question.
Please verify it and tell me if it was ok.
The following two rules check for the presence of query string and redirect to the no-query string version of the page:
Since you are worried about search engines crawling wrong version of page, consider changing to
R=301
once you've tested. Also, you might want to consider returning a 404 error to discourage the use of query strings and tell the search engines that there is no such thing ashttp://mydomain.com/page/?1234
.