@kumawathemant032 Thanks for your message.
We aren’t sure of what exact way you tried using the X-Robots tag to implement this, but that is the exact way we would recommend. How to implement this successfully can vary upon server configuration, so unfortunately we can say whether a code snippet will definitely work for you.
Especially since implementing the code to make this change would be placed in the .htaccess file (for Apache), which can be a very delicate file to edit since even having a single character not correct has the potential to break your entire site, so.
If you are having problems with getting the X-Robots tag successfully inserting a noindex
into the headers of the pdfs, we’d recommend contacting your hosting provider for additional support as they’ll know best which is the best code or method for setting this, as they’ll be familiar with the server configuration.
That being said, I tried a few suggestions for the code to use in .htaccess, such as in the examples found here, and I personally had success with the following ones.
In this example, all .pdf files had the X-Robots tag set to noindex
:
<FilesMatch "\.pdf$">
header set x-robots-tag: noindex
</FilesMatch>
In this example, it allowed for setting multiple file types to noindex
, with the noindex tag also including noarchive
and nosnippet
as well:
<FilesMatch ".(doc|pdf|jpg)$">
Header set X-Robots-Tag "noindex, noarchive, nosnippet"
</FilesMatch>
Again, if these examples don’t work for you, it’s not something we’d be able to troubleshoot as whether they are successful can depend on server configuration.
Also, one last thing, when testing whether the noindex
has been successfully added to the header, we’d recommend using terminal/command prompt to verify this. For example, I use the following command to check the file:
curl -I https://latestpdf.com/wp-content/uploads/2022/11/Venus-Tools-Product-Price-List.pdf