Hello!
I was wondering if someone might be kind enough to help me? I'm trying to noindex a few directories and files of a site using the X-Robots-Tag in the .htaccess file and was wondering if someone could check my code before I upload the file in case everything goes horribly wrong - I'm fairly new to .htaccess and don't want to break the site! I believe I have to do it this way as all of the URLs (there are thousands) have been indexed by Google so I don't think just disallowing them in Robots.txt is good enough, and I can't just noindex each page as I'd be doing it for years!
Below are a few example URLs and what I've done in the .htaccess to try and noindex them:
http://www.example.com/index.php?action=highscores&gameid=885&type=overall&p=1770
<IfModule mod_headers.c>
<FilesMatch "^index.php\?action=highscores?$">
Header set X-Robots-Tag: "noindex"
</FilesMatch>
</IfModule>
http://www.example.com/blog/category/new-games/page/51/
<IfModule mod_headers.c>
<FilesMatch "^blog/category/?$">
Header set X-Robots-Tag: "noindex"
</FilesMatch>
</IfModule>
http://www.example.com/games/1057/play.html
<IfModule mod_headers.c>
<FilesMatch "^play\.html$">
Header set X-Robots-Tag: "noindex, nofollow"
</FilesMatch>
</IfModule>
http://www.example.com/rate_aus.php&gameid=1312
<IfModule mod_headers.c>
<FilesMatch "^rate_?$">
Header set X-Robots-Tag: "noindex"
</FilesMatch>
</IfModule>
I also need to redirect URLs with underscores to their (already existing) counterparts with hyphens, e.g.:
http://www.example.com/games/example_game_name.html
to
http://www.example.com/games/example-game-name.html
I've coded this as:
RewriteCond %{QUERY_STRING} ^.+$
RewriteRule ^_$ -? [L,R=301,NC]
Would I then also need to noindex the underscored URLs to avoid duplicate content? Duplicates are currently a big issue and the main reason for most of this work!
I know it's a massive ask, but if anyone could check these and let me know if I'm completely out, it would be helpful. Normally I'm all about the trial and error, but I know .htaccess files are fragile beasts and I don't want to break anything!
Thanks :)