我只想在GoogleBot或BingBot请求时动态地构建站点地图,然后将其保存到sitemap.xml,以及其他用户请求时只显示已经创建的站点地图。 XML。这个怎么做 ?配置appache在google-bot请求站点地图时执行php
编辑
如何成为sitemap.php列为sitemap.xml?
我只想在GoogleBot或BingBot请求时动态地构建站点地图,然后将其保存到sitemap.xml,以及其他用户请求时只显示已经创建的站点地图。 XML。这个怎么做 ?配置appache在google-bot请求站点地图时执行php
如何成为sitemap.php列为sitemap.xml?
如果您想将文件保存为.xml并执行它作为一个PHP文件,你需要这些方针的东西添加到您的.htaccess文件:
AddType x-mapp-php5 .php .xml
我想只处理一些指定的XML文件作为PHP,而不是所有的XML文件。可能吗 ? – Sourav 2012-02-23 03:38:11
XML文件仍将以XML文件的形式工作 - 但如果在那里有任何PHP,那么这将工作两个。可以将其视为对现有XML文件功能的提升。 – BenOfTheNorth 2012-02-23 11:10:35
应该通过htaccess的或服务器端脚本来完成
的htaccess: redirect all bots using htaccess apache
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;
}
Atention这强烈地受到谷歌劝阻。我只发布这个'因为有时它可能是有用的。
编辑 它总是令我惊讶的是重新发明车轮的能力。如果有人想生成站点地图,请看看: http://code.google.com/p/sitemap-generators/wiki/SitemapGenerators
还有一些付费服务。
我会补充一点,注意sitemap.xml文件是最好的生成和存储在网络服务器上的静态文件。当然,PHP可以用来生成它,而不是在每次从谷歌机器人访问期间实时。 – quickshiftin 2012-02-20 06:31:42
你的问题是有关 - 是关于如何构建站点地图,或者如何检测搜索引擎机器人? – 2012-02-19 14:39:02