.htaccessserver-sideweb-development-server

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


I found on Google that I can noindex/nofollow using the X-Robots-Tag. There are plenty of webpages where they tell me how to do that on single files, entire websites, and directories. This is the way I’m supposed to do it for a single file:

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

But I need to noindex more than one file in a website and have’t been able to figure out how to do it. I have searched in Google and stackoverflow, but haven’t found the answer yet. Can anybody help me please?


Solution

  • You just have to use the file name without the path and Apache applies the rule to any file in the file system with the provided file name. So this is what I finally did, which I think did the trick for me:

    # 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>
    

    This article helped me. https://gist.github.com/ankurk91/ee339291c6666dcba794