Hide a single content block from search engines?
Posted
by
jonas
on Stack Overflow
See other posts from Stack Overflow
or by jonas
Published on 2012-12-03T11:01:57Z
Indexed on
2012/12/03
11:03 UTC
Read the original article
Hit count: 264
A header is automatically added on top of each content URL, but its not relevant for search and messing up the all the results beeing the first line of every page (in the code its the last line but visually its the first, which google is able to notice)
Solution1:
You could put the header (content to exculde from google searches)
in an iframe with a static url domain.com/header.html and a <meta name="robots" content="noindex" />
?
- are there takeoffs of this solution?
Solution2: You could deliver it conditionally by apache mod rewrite, php or javascript
-takeoff(?): google does not like it? will google ever try pages with a standard users's useragent and compare?
-takeoff: The hidden content will be missing in the google cache version as well...
example: add-header.php:
<?php
$path = $_GET['path'];
echo file_get_contents($_SERVER["DOCUMENT_ROOT"].$path); ?>
apache virtual host config:
RewriteCond %{HTTP_USER_AGENT} !.*spider.* [NC]
RewriteCond %{HTTP_USER_AGENT} !Yahoo.* [NC]
RewriteCond %{HTTP_USER_AGENT} !Bing.* [NC]
RewriteCond %{HTTP_USER_AGENT} !Yandex.* [NC]
RewriteCond %{HTTP_USER_AGENT} !Baidu.* [NC]
RewriteCond %{HTTP_USER_AGENT} !.*bot.* [NC]
RewriteCond %{SCRIPT_FILENAME} \.htm$ [NC,OR]
RewriteCond %{SCRIPT_FILENAME} \.html$ [NC,OR]
RewriteCond %{SCRIPT_FILENAME} \.php$ [NC]
RewriteRule ^(.*)$ /var/www/add-header.php?path=%1 [L]
© Stack Overflow or respective owner