X-Robots-Tag - Noindex .htaccess 中的几个文件

X-Robots-Tag - Noindex several files in .htaccess

我在 Google 上发现我可以 noindex/nofollow 使用 X-Robots-Tag。有很多网页告诉我如何在单个文件、整个网站和目录上执行此操作。这是我应该为单个文件做的方式:

    <FilesMatch "robots.txt">
    Header set X-Robots-Tag "noindex"
    </FilesMatch>

但我需要在一个网站上对多个文件不编制索引,但一直无法弄清楚该怎么做。我在 Google 和 Whosebug 中搜索过,但还没有找到答案。有人可以帮我吗?

我花了几个星期的时间才尝试使用三目录深的路径来对 .htaccess 中的某些文件进行无索引。我一直在目瞪口呆地想弄清楚该怎么做,最后发现您只需要使用不带路径的文件名,并且 Apache 将规则应用于文件系统中具有提供文件的任何文件姓名。所以这就是我最终所做的,我认为这对我有用:

# Prevent search engines from indexing some files
<FilesMatch "^(about-cosma.html|footer.html|menu.html|acerca-de-cosma.html|es-footer.html|es-menu.html)">
Header set X-Robots-Tag "noindex, nofollow"
</FilesMatch>

这篇文章帮助了我。 https://gist.github.com/ankurk91/ee339291c6666dcba794