拒绝访问但允许机器人(即 Google)访问 sitemap.xml

问题描述 投票:0回答:3

是否有一种方法可以仅允许 Google、Yahoo 或其他搜索引擎机器人等机器人访问我的站点地图(位于 http://www.mywebsite.com/sitemap.xml)。是否可以不允许用户直接访问而只允许机器人访问?

web-crawler
3个回答
5
投票

基本上不行,但是您可以使用用户代理字符串执行某些操作并禁止访问(假设是 Apache)

<Location /sitemap.xml>
  SetEnvIf User-Agent GodBot GoAway=1
  Order allow,deny
  Allow from all
  Deny from env=!GoAway
</Location>

但是正如它所说的here(我在哪里找到语法)

警告:

用户代理的访问控制是一种 技术不可靠,因为 User-Agent 标头可以设置为 任何事情,随心所欲 最终用户。


2
投票

在我的来源中它是红色的:

$ip = $_SERVER["REMOTE_PORT"];
$host = gethostbyaddr($ip);

if(strpos($host, ".googlebot.com") !== false){
    readfile("sitemap.xml");
}else{
    header("Location: /");


0
投票

站点地图.php

<?php

    $ip = $_SERVER["REMOTE_PORT"];
    $host = gethostbyaddr($ip);

    if(strpos($host, ".googlebot.com") !== false){
        readfile("sitemap.xml");
    }else{
        header("Location: /");
    }
© www.soinside.com 2019 - 2024. All rights reserved.