25. 4月 2010 · Write a comment · Categories: SEO

phpなどで作った動的なページからサイトマップをつくるためにどうしたらいいか調べる。ググると

http://neoinspire.net/archives/68

のページが参考になる(感謝です)。test.phpはこんな感じ

<?php
require(“Class.Sitemap.php”);
//URLデータ作成
$array[0]['url'] = “http://www.a.com”; //url
$array[0]['lastmod'] = “2008-01-01″; //LastModified Date
$array[0]['changefreq'] = “daily”; //Change Frequency
$array[0]['priority'] = “0.5″; //Priority

//以下必要なだけArrayに突っ込む
$array[1]['url'] = “http://www.a.com”;
$array[1]['lastmod'] = “2008-01-02″;
$array[1]['changefreq'] = “monthly”;
$array[1]['priority'] = “0.5″;

//クラスを呼び出してGO
$Sitemap = new Sitemap();
$Sitemap->create($array);
$Sitemap->output();

?>

こちらにおいてあるソースをほぼまるまる使ったのだが

Cannot modify header information – headers already sent by・・・・・・・

というようなエラーがでる原因がよくわからなかったが

http://sb.xrea.com/showthread.php?t=12693

を見てutf-8のbomなしでセーブしアップロードするとうまく動いた。

<?xml version=”1.0″ encoding=”UTF-8″ ?>

- <urlset xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance xsi:schemaLocation=”http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/09/sitemap.xsd xmlns=”http://www.sitemaps.org/schemas/sitemap/0.9>
- <url>
  <loc>http://www.a.com</loc>
  <lastmod>2008-01-01</lastmod>
  <changefreq>daily</changefreq>
  <priority>0.5</priority>
  </url>
- <url>
  <loc>http://www.a.com</loc>
  <lastmod>2008-01-02</lastmod>
  <changefreq>monthly</changefreq>
  <priority>0.5</priority>
  </url>
  </urlset>

test.phpにアクセするとこんな感じのサイトマップが表示されます。