【发布时间】:2011-07-04 09:40:15
【问题描述】:
有没有一种方法可以让您只允许 Google、Yahoo 或其他搜索引擎机器人等机器人访问我位于 http://www.mywebsite.com/sitemap.xml 的站点地图。这是否可能不允许用户直接访问而只允许机器人访问?
【问题讨论】:
标签: web-crawler robot
有没有一种方法可以让您只允许 Google、Yahoo 或其他搜索引擎机器人等机器人访问我位于 http://www.mywebsite.com/sitemap.xml 的站点地图。这是否可能不允许用户直接访问而只允许机器人访问?
【问题讨论】:
标签: web-crawler robot
基本上没有,但你可以对用户代理字符串做一些事情并禁止访问(假设是 Apache)
<Location /sitemap.xml>
SetEnvIf User-Agent GodBot GoAway=1
Order allow,deny
Allow from all
Deny from env=!GoAway
</Location>
但正如它所说的here(我在哪里找到了语法)
警告:
User-Agent 的访问控制是一种 不可靠的技术,因为 User-Agent 标头可以设置为 什么都可以,随心所欲 最终用户。
【讨论】:
在我的源代码中它是红色的:
$ip = $_SERVER["REMOTE_PORT"];
$host = gethostbyaddr($ip);
if(strpos($host, ".googlebot.com") !== false){
readfile("sitemap.xml");
}else{
header("Location: /");
【讨论】:
sitemap.php
<?php
$ip = $_SERVER["REMOTE_PORT"];
$host = gethostbyaddr($ip);
if(strpos($host, ".googlebot.com") !== false){
readfile("sitemap.xml");
}else{
header("Location: /");
}
【讨论】: