SEO」タグアーカイブ

HTTP_Request2を用いたGoogle へのサイトマップ送信

Googleへサイトップを送信する際、PHP PEARのHTTP_Request2を使う方法は下記の通り。

[php]
<?php
require_once ‘HTTP/Request2.php’;

$uri = ‘http://www.google.com/webmasters/tools/ping’;
$sitemap_uri = ‘http://www.example.com/sitemap.xml’;

try{
$request2 = new HTTP_Request2($uri);
$request2—>setMethod(HTTP_Request2::METHOD_POST);
$request2->addPostParameter(‘sitemap’, $sitemap_uri);
$result = $request2->send();
echo $result->getBody();
} catch( HTTP_Request2_Exception $e ){
exit($e->getMessage());
} catch (Exception $e){
exit($e->getMessage());
}
?>
[/php]

上記実行後、下記のように表示されたらリクエストの送信は成功。

Sitemap Notification Received
Your Sitemap has been successfully added to our list of Sitemaps to crawl. If this is the first time you are notifying Google about this Sitemap, please add it via http://www.google.com/webmasters/tools/ so you can track its status. Please note that we do not add all submitted URLs to our index, and we cannot make any predictions or guarantees about when or if they will appear.