配置apache以在google bot请求sitemap时执行php

配置apache以在google bot请求sitemap时执行php,php,xml,mod-rewrite,sitemap,Php,Xml,Mod Rewrite,Sitemap,我只想在GoogleBot或BingBot请求时动态构建一个站点地图,然后将其保存到sitemap.xml,当其他用户请求时,只显示已经创建的sitemap.xml。如何做到这一点 编辑 如何将sitemap.php作为sitemap.xml提供?应该通过htaccess或服务器端脚本完成 htaccess: PHP:类似于 //returns 1 if the user agent is a bot function is_bot($user_agent) { //if no user

我只想在GoogleBot或BingBot请求时动态构建一个站点地图,然后将其保存到sitemap.xml,当其他用户请求时,只显示已经创建的sitemap.xml。如何做到这一点

编辑
如何将sitemap.php作为sitemap.xml提供?

应该通过htaccess或服务器端脚本完成

htaccess:

PHP:类似于

//returns 1 if the user agent is a bot
function is_bot($user_agent)
{
  //if no user agent is supplied then assume it's a bot
  if($user_agent == "")
    return 1;

  //array of bot strings to check for
  $bot_strings = Array(  "google",     "bot",
            "yahoo",     "spider",
            "archiver",   "curl",
            "python",     "nambu",
            "twitt",     "perl",
            "sphere",     "PEAR",
            "java",     "wordpress",
            "radian",     "crawl",
            "yandex",     "eventbox",
            "monitor",   "mechanize",
            "facebookexternal"
          );
  foreach($bot_strings as $bot)
  {
    if(strpos($user_agent,$bot) !== false)
    { return 1; }
  }

  return 0;
}
aEntion谷歌强烈反对这种做法。我只是发布这个,因为有时候它会很有用

编辑 重新发明轮子的能力总是让我感到惊讶。如果有人想生成网站地图,请查看:


还有一些付费服务。

如果要将文件另存为.xml并作为PHP文件执行,则需要在.htaccess文件中添加以下内容:

AddType x-mapp-php5 .php .xml

你的问题是关于什么的?是关于如何构建站点地图,还是如何检测搜索引擎机器人?我要补充一点,注意sitemap.xml文件是最好的生成文件,并作为静态文件存储在Web服务器上。当然,PHP可以用来生成它,只是在每次访问google bot时都不是实时生成的。有可能吗?XML文件仍然可以作为XML文件使用——但如果有PHP,那就有两种。可以将其视为对现有XML文件功能的增强。