X-Robots noindex dedicated page in .htaccess

Is it possible to "noindex follow" a specific page using x robots in .htaccess?

I found several instructions for noindexing file types, but I can not find instructions for noindex on one page, and what I have tried so far has not worked.

This is the page I'm looking at noindex for:

http://www.examplesite.com.au/index.php?route=news/headlines 

This is what I have tried so far:

 <FilesMatch "/index.php?route=news/headlines$"> Header set X-Robots-Tag "noindex, follow" </FilesMatch> 

Thank you for your time.

+6
source share
4 answers

It seems impossible to match request parameters from a .htaccess file. Here is a list of what you can map: http://httpd.apache.org/docs/2.2/sections.html

It will be much easier to do in your script. If you are using PHP try:

 header('X-Robots-Tag: noindex, follow'); 

You can easily create conditions on $ _GET, REQUEST_URI, etc.

+9
source
 RewriteEngine on RewriteBase / #set env variable if url matches RewriteCond %{QUERY_STRING} ^route=news/headlines$ RewriteRule ^index\.php$ - [env=NOINDEXFOLLOW:true] #only sent header if env variable set Header set X-Robots-Tag "noindex, follow" env=NOINDEXFOLLOW 

FilesMatch works with (local) files, not URLs. Therefore, it will try to match only a portion of the /index.php URL. <location> would be more appropriate, but as far as I can read from the documentation, repetitions are not allowed here. So, I ended up with the above solution (I really liked this call). Although php would be a more obvious place for this, it is up to you.

The solution requires mod_rewrite and mod_headers, of course.

+4
source

Note that you will need the mod_headers module to set the headers.

Although, as others have said, it is better to use the php tag. This does not work?

0
source

According to Google, the syntax will be slightly different:

 <Files ~ "\.pdf$"> Header set X-Robots-Tag "noindex, nofollow" </Files> 

https://developers.google.com/webmasters/control-crawl-index/docs/robots_meta_tag

0
source

All Articles