I found a similar question with a great answer for removing a single URL parameter. However, what if I have 20+ URL parameters that I don't want indexed?
Also, in the example solution below, it is assuming that you want to specify a parameter range (ex: ?id=0
to ?id=9
)... In my situation I would simply want to not index anything with the ?id
parameter at all, regardless of what follows in the url string. Let's also say that I would not want to index the ?start
and ?Page
parameters either... Can someone help me out with a revised version of the following code?
For NOINDEX:
<IfModule mod_rewrite.c>
RewriteCond %{QUERY_STRING} ^id=([0-9]*)$
RewriteRule .* - [E=NOINDEX_HEADER:1]
</IfModule>
<IfModule mod_headers.c>
Header set X-Robots-Tag "noindex, follow" env=NOINDEX_HEADER
</IfModule>
For CANONICAL:
<IfModule mod_rewrite.c>
RewriteCond %{QUERY_STRING} ^id=([0-9]*)$
RewriteRule .* - [E=CANONICAL_HEADER:1]
</IfModule>
<IfModule mod_headers.c>
Header set Link '%{HTTP_HOST}%{REQUEST_URI}e; rel="canonical"' env=CANONICAL_HEADER
</IfModule>
Thank you @Evgeniy and @JohnMueller for the above code.
Reference: How to correctly remove parameters from the Google index?