目次

検索エンジン用のサイトマップ?

サイトマップといえば、一つのウェブサイト全体の構成をが見てわかりやすいように、サイトマップページが作成してあって、そこに、コンテンツ一覧のようなものが書かれていますね。

ウェブサイトの全ページへのリンクとまではいかなくても、全体の目次のように見ることができるページです。

同様に、検索エンジンから見てサイトのページがわかりやすいように、検索エンジン用のサイトマップを作成しておくこともできるようです。

WordPress で作成した当ブログでも検索エンジン用のサイトマップを作成してみようと思い、その仕様を調べてみたところ、以下のページが見つかりました。

上のリンクを見てみると XML , TXT , RSS などの形式でサイトマップを作成できるようです。検索エンジン用のサイトマップの詳細な仕様が掲載してあります。

まずは、この中から XML 形式でのサイトマップの記述方法を試してみいたいと思います。

目次まで戻る

作成場所を確認。

下記 URL に詳細に説明してありますが、サイトマップの設置場所(保存場所)は重要です。

当ブログでサイトマップ設置の試行をした時、最初は当ブログのテーマフォルダの

https://pulogu.net/wordpress/wp-content/themes/twentysixteen-bootstrap-v3-child/

の中に

sitemap.xml

を設置してみました。

ところが、この「 sitemap.xml 」が正常に認識されませんでした。 sitemaps.org のドキュメントをよくよく読んでみると、原因がわかりました。

https://pulogu.net/wordpress/wp-content/themes/twentysixteen-bootstrap-v3-child/

の中に

sitemap.xml

を設置した場合、サイトマップの URL としては、

https://pulogu.net/wordpress/wp-content/themes/twentysixteen-bootstrap-v3-child/sitemap.xml

になります。

これが、原因でした。

https://pulogu.net/wordpress/wp-content/themes/twentysixteen-bootstrap-v3-child/sitemap.xml

の場合、

https://pulogu.net/wordpress/wp-content/themes/twentysixteen-bootstrap-v3-child/

以下にある URL しか含めることが出来ないようです。

とうことは、

https://pulogu.net/wordpress/wp-content/themes/twentysixteen-bootstrap-v3-child/category/blog/

とか、

https://pulogu.net/wordpress/wp-content/themes/twentysixteen-bootstrap-v3-child/tag/wordpress/

のような URL しか含めることが出来ないことになってしまいます。

https://pulogu.net/category/blog/
https://pulogu.net/tag/wordpress/

を含めたいのです。

というわけで、当ブログの検索エンジン用のサイトマップは、「 https://pulogu.net/ 」に「 sitemap.xml 」を保存して、最終的に

https://pulogu.net/sitemap.xml

としました。この場所は、インストール時の WordPress フォルダと横並びの同じ場所です。

以下の URL が当ブログ XML サイトマップの場所になります。「 https://pulogu.net/ 」から始まる URL を記載できています。

テキストファイル版も作っていますが、ウェブマスターツールへの登録は、 XML 形式のみです。

目次まで戻る

XML 形式のサイトマップ記述方法

XML のコード :

<!-- 下の行は必須です。 <?xml の前のここのコメントは削除しないとエラーになったような記憶が。 -->
<?xml version="1.0" encoding="UTF-8"?>
<!-- 下の行は必須です。 --> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

<!-- ここから 1 個目の URL -->
<!-- ここから必須です。 --> <url>
<!-- <loc></loc> の中に URL を記述します。 -->     <loc>https://pulogu.net/</loc> </url>
   <!-- ここまで必須です。 -->
   <!-- ここまで 1 個目の URL -->
<!-- ここから 2 個目の URL -->
<url>
<!-- <loc></loc> は含んでいなければなりません。例は当ブログの「当ブログについて」のページの URL 。末尾にスラッシュ( / の記号)を含む 2048 文字以下の URL 。ただ、末尾にスラッシュを含まない場合はどうなるのか実テスト中です。 -->
<loc>https://pulogu.net/about-this-blog/</loc>
<!-- オプションでページの最終更新日を設定可能です。年、月、日時、秒単位など。例は年月日。4桁-2桁-2桁になっています。 -->
<lastmod>2016-08-31</lastmod>
<!--オプションでページの更新頻度を設定可能です。年、月、週、日、時単位など。例は日間隔。 -->
<changefreq>daily</changefreq>
<!-- オプションでページの優先度を設定可能です。設定値は 0.0 から 1.0 。例は規定値の 0.5 。 -->
<priority>0.5</priority>
</url>
<!-- ここまで 2 個目の URL -->

<!-- 以降 <url><loc></loc><url> の繰り返し。最大 50000 個。 XML のファイルサイズ 10 MB 以下。 -->

<!-- 下の行は必須です。 -->
</urlset>

コメントばかりで少し見にくいので。

XML のコメント抜きのコード :

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
    <loc>https://pulogu.net/</loc> </url>
<url>
<loc>https://pulogu.net/about-this-blog/</loc>
<lastmod>2016-08-31</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
</urlset>

私自身、 XML のことはさっぱりですが、さほど難しい書式ではなくて安心しました。ちなみに上の上のコードの <!-- --> の部分は XML のコメントとして書いていますので、実際には記述する必要はありません。

記述のルールとしては、

<?xml version="1.0" encoding="UTF-8"?> <!-- これは仕様のようです。 -->
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <!-- これは仕様のようです。 -->

から始めて、必須の <url><loc></loc></url> タグをサイトマップとして送信したい URL の数だけ繰り返し記述します。

<url>
<!-- 下の行の <loc></loc> の中身の URL は自サイトのものに変更します。 --> <loc>https://pulogu.net/</loc> </url>
<!-- 上記 <url><loc></loc><url> を URL の数だけ繰り返し -->

最後に、

</urlset> <!-- これは仕様のようです。 -->

で閉じて完了です。

XML 形式のサイトマップのポイントとしては、オプションでページの最終更新日( <lastmod></lastmod> タグ )、更新頻度( <changefreq></changefreq> タグ )、優先度( <priority></priority> タグを設定できることでしょうか。

目次まで戻る

テキストファイル形式

テキストファイル形式の場合、 URL を 1 行づつ記載していけば良いみたいです。 XML と比べるとサイトマップ作成作業は容易に思います。

https://pulogu.net/
https://pulogu.net/about-this-blog/

私の場合、パソコン側で文字コードを UTF-8 、改行コードを LF でテキストファイルを保存後、 FTP ソフトでサーバにアップロードしても、サーバ側でテキストファイルを開くと文字コード SJIS , 改行コード CRLF に戻ってしまいます。

テキストファイルの文字に日本語が入っていると、サーバ側のテキストファイルを開いても UTF-8 で開きます。なぜなのか原因がわかりません。

目次まで戻る

RSS 形式

当ブログトップページの HTML ソース :

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>pulogu.net &#8211; プログラム、その他のメモをとるためのブログです。</title>
<link rel="alternate" type="application/rss+xml" title="pulogu.net &raquo; フィード" href=
"https://pulogu.net/feed/" /> <!-- RSS フィードの URL -->
<link rel="alternate" type="application/rss+xml" title="pulogu.net &raquo; コメントフィード" href="https://pulogu.net/comments/feed/" />

RSS フィードを配信しているブログの場合、 RSS フィードの URL を指定することもできるようです。RSS フィードの URL は上のソースの、

https://pulogu.net/feed/

の部分になります。 WordPress は RSS フィード配信機能があるので、この方法も早くてよいかもしれません。

WordPress から配信されているフィードの中身は以下のような XML データになっているようです。

当ブログ RSS フィードへのリンク :

当ブログの RSS フィードの中身 :

<!-- XML 形式のようです。 -->
<?xml version="1.0" encoding="UTF-8"?>

<!-- RSS のバージョンは 2.0 のようです。 -->
<rss version="2.0"
    xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:wfw="http://wellformedweb.org/CommentAPI/"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:atom="http://www.w3.org/2005/Atom"
    xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
    xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
    >

  <!-- <rss><channel></channel></rss> という構造のようです。 -->
    <channel>

     <!-- 当ブログの基本的な情報が列挙されている部分のようです。 -->
        <title>pulogu.net</title>
        <atom:link href="https://pulogu.net/feed/" rel="self" type="application/rss+xml" />
        <link>https://pulogu.net</link>
        <description>プログラム、その他のメモをとるためのブログです。</description>
        <lastBuildDate>Thu, 01 Sep 2016 05:35:38 +0000</lastBuildDate>
        <language>ja</language>
        <sy:updatePeriod>hourly</sy:updatePeriod>
        <sy:updateFrequency>1</sy:updateFrequency>
        <generator>https://wordpress.org/?v=4.6</generator>

<!-- 画像サイズからしてファビコン favicon でしょうか。 -->    
        <image>
            <url>https://pulogu.net/wordpress/wp-content/uploads/2016/04/cropped-pulogu_logo-4-32x32.png</url>
            <title>pulogu.net</title>
            <link>https://pulogu.net</link>
            <width>32</width>
            <height>32</height>
        </image>
    
<!-- ここから一つの記事のようです。 -->
        <item>
            <title>記事のタイトル</title>
<!-- <link></link> タグの中身がサイトマップの URL として認識されるようです。 -->
            <link>https://pulogu.net/blog/php/dealing-with-json-in-php/</link>
            <comments>https://pulogu.net/blog/php/dealing-with-json-in-php/#respond</comments>
            <pubDate>Sat, 20 Aug 2016 06:52:01 +0000</pubDate>
            <dc:creator><![CDATA[Editer]]></dc:creator>
            <category><![CDATA[PHP]]></category>
            
            <guid isPermaLink="false">https://pulogu.net/?p=924</guid>
            <description><![CDATA[記事の抜粋]]></description>
            <content:encoded><![CDATA[記事の本文]]></content:encoded>
            <wfw:commentRss>https://pulogu.net/blog/php/dealing-with-json-in-php/feed/</wfw:commentRss>
            <slash:comments>0</slash:comments>
        </item>
     <!-- ここまでが一つの記事のようです。 <item></item> の間。 -->
    
    <!-- 以降 <item></item> が繰り返されています。 -->
        <item>
            <title>記事のタイトル</title>
            <link>https://pulogu.net/blog/php/htmlspecialchars-to-var_dump/</link>
            <comments>https://pulogu.net/blog/php/htmlspecialchars-to-var_dump/#respond</comments>
            <pubDate>Fri, 19 Aug 2016 07:57:20 +0000</pubDate>
            <dc:creator><![CDATA[Editer]]></dc:creator>
            <category><![CDATA[PHP]]></category>
            <category><![CDATA[htmlspecialchars]]></category>
            <category><![CDATA[var_dump]]></category>
            
            <guid isPermaLink="false">https://pulogu.net/?p=915</guid>
            <description><![CDATA[記事の抜粋]]></description>
            <content:encoded><![CDATA[記事の本文]]></content:encoded>
            <wfw:commentRss>https://pulogu.net/blog/php/htmlspecialchars-to-var_dump/feed/</wfw:commentRss>
            <slash:comments>0</slash:comments>
        </item>
    
        <item>
            <title>記事のタイトル</title>
            <link>https://pulogu.net/blog/web-services/bing-webmaster-tools/</link>
            <comments>https://pulogu.net/blog/web-services/bing-webmaster-tools/#respond</comments>
            <pubDate>Fri, 19 Aug 2016 06:18:06 +0000</pubDate>
            <dc:creator><![CDATA[Editer]]></dc:creator>
            <category><![CDATA[ウェブサービス]]></category>
            <category><![CDATA[Bing]]></category>
            <category><![CDATA[ウェブマスターツール]]></category>
            
            <guid isPermaLink="false">https://pulogu.net/?p=912</guid>
            <description><![CDATA[記事の抜粋]]></description>
            <content:encoded><![CDATA[記事の本文]]></content:encoded>
            <wfw:commentRss>https://pulogu.net/blog/web-services/bing-webmaster-tools/feed/</wfw:commentRss>
            <slash:comments>0</slash:comments>
        </item>

    </channel>

</rss>

目次まで戻る

WordPress から自動生成

WordPress から自動で作成できるようにするにはどうすればいいのか調査中です。検索エンジン用のサイトマップを作成してくれる WordPress プラグインもあるようです。

目次まで戻る

参考情報

以上、閲覧ありがとうございました。

目次まで戻る

同じカテゴリの投稿(ウェブサービス)

前後の投稿