X-Robots-Tag HTTP Header

No Index

header("X-Robots-Tag: noindex", true);

No Index and No Follow

header("X-Robots-Tag: noindex, nofollow", true);

Apache Server Implemenation

Implemenation on the .htaccess file

<FilesMatch ".(txt|docx)$">
Header set X-Robots-Tag "noindex, noarchive, nosnippet"

No Index Specific File in Apache

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

Ngnix server Implemenation

location ~* \.(doc|pdf)$ {
 add_header X-Robots-Tag "noindex, noarchive, nosnippet";

No Index Specific File in Ngnix

location = example.txt {
 add_header X-Robots-Tag "noindex";