Reputation: 2274
For some reason, Google is indexing some of my pages that are called via AJAX and return JSON data for my website. Those pages aren't meant to be visited so I don't want them to appear on Search.
so, in .htaccess
, I'm trying to set a header for a particular folder that holds all the AJAX files.
I've tried both
<Files ~ "ajax\.php$">
Header set X-Robots-Tag "noindex, nofollow"
</Files>
and
<Files ~ "\ajax\.php$">
Header set X-Robots-Tag "noindex, nofollow"
</Files>
but none of those seem to work.
<Files ~ "\.php$">
Header set X-Robots-Tag "noindex, nofollow"
</Files>
however works, but then all my php pages get this header, which is not what I'm looking for of course.
Upvotes: 0
Views: 2697
Reputation: 785471
You may use it like this:
SetEnvIfNoCase Request_URI "ajax\.php$" ROBOTAG
Header set X-Robots-Tag "noindex, nofollow" env=ROBOTAG
Upvotes: 0
Reputation: 2856
You should add the <Directory>
tag to add it only to files in the ajax
directory and then do <FilesMatch>
to add it to .PHP
files only.
<Directory "/ajax">
<FilesMatch "\.php$">
#put your header set stuff here
Header set X-Robots-Tag "noindex, nofollow"
</FilesMatch>
</Directory>
Check out this link for some more help.
https://httpd.apache.org/docs/2.4/expr.html#examples
Upvotes: 0