1

I am using parameters on some subpages, but google index them in the search results for some reason in the homepage URL.

How can I please remove them in .htaccess only for homepage?

remove ?a=123 here:

  • example.com/?a=123 (result: example.com)

don't remove it here:

  • example.com/subpage/event.php?a=123

I found this, but I don't know how to apply it only for homepage:

RewriteCond %{QUERY_STRING} .
RewriteRule (.*) $1?
MrWhite
  • 43,179
  • 8
  • 60
  • 84
leroux
  • 37
  • 3

1 Answers1

2

Use this:

RewriteEngine On
RewriteCond %{QUERY_STRING} .
RewriteRule ^/?$ / [R=301,L,QSD]
  • %{QUERY_STRING} . means "query string contains at least one character"
  • ^/?$ is "just the home page" -- ie the URL path only consists of an optional slash
  • [R=301] Redirects the request (to change the URL)
  • [L] is the last rewrite rule so that it doesn't conflict with later ones
  • [QSD] is "query string delete" so that rewrite doesn't try to append the query string to the redirect
Stephen Ostermiller
  • 23,933
  • 14
  • 88
  • 109