RSSフィードをFeedBurnerに委譲しようと思う。
他のBlog等でも紹介されているように、下記のような理由です。
手順としては、下記のような手順になる。
他のBlog等でも紹介されているように、下記のような理由です。
- RSSフィードへのトラフィックの軽減
- Movable TypeでのRSSフィード作成の負荷軽減
- フィードの購読者などの情報の把握
手順としては、下記のような手順になる。
- FeedBurnerへの登録
- RSSフィードの生成方法の変更
- RSSフィードへのアクセスをFeedBurnerへ転送
FeedBurnerへの登録
Feedburnerでアカウントを作成し、Feedburner側へはfeedburner.xmlを送信するようにする。
Movable Type側で、Atomを生成しているテンプレートの生成ファイル名を変更し、保存、再構築する。
念のため、生成したatomがちゃんと読めるか、ブラウザーでアクセスし、問題なければFeedburner側の設定情報を更新する。RSSフィードの生成方法の変更
Movable Type 4.1では、RSSの作成部分は「テンプレートモジュール」の「ヘッダー」の最初の方、<mt:setvatblock>タグの部分になる。<mt:setvarblock name="html_head" prepend="1">
<MTIf name="main_template">
<link rel="alternate" type="application/atom+xml" title="Atom" href="<$MTLink template="atom"$>" />
<link rel="alternate" type="application/rss+xml" title="RSS" href="<$MTLink template="rss"$>" />
<MTUnless name="main_index">
<link rel="start" href="<$MTBlogURL$>" title="Home" />
</MTUnless>
<$MTCCLicenseRDF$>
</MTIf>
</mt:setvarblock>
今回の場合、AtomとRSSの両方をFeedBurnerに変更するため、
<mt:setvarblock name="html_head" prepend="1">
<MTIf name="main_template">
<link rel="alternate" type="application/atom+xml" title="Atom" href="http://feeds.feedburner.jp/tf_blog" />
<link rel="alternate" type="application/rss+xml" title="RSS" href="http://feeds.feedburner.jp/tf_blog" />
<MTUnless name="main_index">
<link rel="start" href="<$MTBlogURL$>" title="Home" />
</MTUnless>
<$MTCCLicenseRDF$>
</MTIf>
</mt:setvarblock>
に変更する。Feedburner側でRSSとAtomの両方の形式に対応してくれるので、同じものを指定している。
Movable TypeはRSD、RSS、Atomの3種類のフィードをインデックステンプレート再構築時に生成しているので、RSDとRSSは生成しないようにチェックを外しておく。
RSSフィードへのアクセスをFeedBurnerへ転送
Webサーバー側でRSSフィードへのアクセスをFeedBurnerへ転送するのだが、Apacheを使っているのでmod_rewriteで対応する。で、この処理をどこでやるのかが悩ましい・・・。
- Apacheの設定ファイル側で指定する。
- .htaccessで指定する。
上記のどちらでもできるが、サーバー管理者の視点から考えると、Rewriteルールをみるのにディレクトリの.htaccessにまとめられても見逃す可能性があるので、設定ファイルで指定するのがいいでしょう。
ちなみに、設定ファイルは以下のように分けています。整理整頓は大事です・・・。
$APACHE_ROOT/conf Apache全体の設定、読み込む追加ファイルの指定設定ファイル側に下記のように設定し、apachectl configtestでエラーがないか確認して、stop & start。
/conf.d 読み込むモジュールなどの個別の設定
/virtualhost Virtural Host毎の設定
RewriteEngine on
RewriteRule ^/tf/index\.rdf$ http://feeds.feedburner.jp/tf_blog [R=permanent,L]
RewriteRule ^/tf/index\.xml$ http://feeds.feedburner.jp/tf_blog [R=permanent,L]
RewriteRule ^/tf/atom\.xml$ http://feeds.feedburner.jp/tf_blog [R=permanent,L]
Redirect時に恒久的に移動した旨を伝えてもらうために、permanentを指定する。
ちなみに、こういう感じの返答を返します。
$ telnet blog.on-net.jp 80
Trying 59.106.25.213...
Connected to blog.on-net.jp.
Escape character is '^]'.
GET /tf/index.xml HTTP/1.0
HTTP/1.1 301 Moved Permanently
Date: Wed, 05 Mar 2008 14:07:49 GMT
Location: http://feeds.feedburner.jp/tf_blog
Connection: close
Content-Type: text/html; charset=iso-8859-1
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD>
<TITLE>301 Moved Permanently</TITLE>
</HEAD><BODY>
<H1>Moved Permanently</H1>
The document has moved <A HREF="http://feeds.feedburner.jp/tf_blog">here</A>.<P>
</BODY></HTML>
Connection closed by foreign host.
期待通りの動作をしているのが確認できる。