To fix 404 and problems of domain.com/?
you can have this rewrite code:
ErrorDocument 404 http://domain.com/error404.html
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+\?
RewriteRule ^ /? [R=301,L]
Pergunta
When I visit my "domain.com/?" or "domain.com/?any-other-character-here" it shows my homepage, this caused duplicate results in Google. Web server is Apache.
My code is
ErrorDocument 404 domain.com/error404.html
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.com
RewriteRule (.*) domain.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} \s/+\?\s
RewriteRule ^ /? [R=301,L]
It redirects non-www to www and I added your code in it. But still see domain.com/?any-random-text doesn't redirect to 404
Solução
To fix 404 and problems of domain.com/?
you can have this rewrite code:
ErrorDocument 404 http://domain.com/error404.html
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+\?
RewriteRule ^ /? [R=301,L]