MovableTypeで別ドメインに公開されているTagSearchLinkを公開ドメインに変更する
つまりどういう事かというと、「http://example.com」にインストールしたMTで作った別ドメインのサイトは、タグへのリンクが、「http://1.example.com」ではなく、「http://example.com/mt-search.cgi~」になってしまうのですが、これを、「http://1.example.com/mt-search.cgi~」に、そして、「http://1.example.com/tag/~/」に変換する方法です。
要phpです。
インデックステンプレートにphpファイルを作成
まず、インデックステンプレートを新規作成します。名前はタグとでもしておきましょう。出力ファイルは「tag/index.php」とでも。
そこに以下のようなコードを書きます。
<?php $tagname = urlencode($_GET["tag"]);
if (is_null($tagname)){
$html404 = file_get_contents("<$mt:Blogurl$>404.html");
header("HTTP/1.0 404 Not Found");
print ($html404);
}
else {
$url = "<$mt:CGIPath$>mt-search.cgi?blog_id=<$mt:BlogID$>&tag=".$tagname."&limit=20";
$html = file_get_contents($url);
header("Content-type: text/html; charset=utf-8");
print ($html);
}
?>
何やっているかというと、「tag/index.php?tag=~」の引数付きでアクセスすると、タグページをfile_get_contentsで読み込みにいっています。引数がない場合はエラーページを返しています。
.htaccessでURLを書き換え
同じくインデックステンプレートに.htaccessを作成し、以下のように記述。
RewriteEngine on
RewriteRule ^tag/(.*)/$ /tag/?tag=$1
おなじみmod_rewriteですね。これで、「http://1.example.com/tag/~/」でアクセスできます。
スポンサード・リンク


トラックバックURL