有没有一种方法,你可以只允许机器人,如谷歌,雅虎,或其他搜索引擎机器人到我的网站地图,这是位于http://www.mywebsite.com/sitemap.xml。这是否可能不允许用户直接访问,而只允许访问机器人?
发布于 2011-07-04 17:49:39
基本上不允许访问,但您可以对用户代理字符串执行某些操作并禁止访问(假设是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头完全可以设置为任何内容,最终用户可以随意设置。
发布于 2013-10-03 03:18:21
它在我的源码中是红色的:
$ip = $_SERVER["REMOTE_PORT"];
$host = gethostbyaddr($ip);
if(strpos($host, ".googlebot.com") !== false){
readfile("sitemap.xml");
}else{
header("Location: /");发布于 2011-07-04 18:05:05
sitemap.php
<?php
$ip = $_SERVER["REMOTE_PORT"];
$host = gethostbyaddr($ip);
if(strpos($host, ".googlebot.com") !== false){
readfile("sitemap.xml");
}else{
header("Location: /");
}https://stackoverflow.com/questions/6569706
复制相似问题