hiki.cgi?hoge じゃなく hoge.html でアクセスしてもらうには
English version may be found at http://hikiwiki.org/en/PretendStaticURL.html.
hiki.cgi?hoge じゃなく hoge.html でアクセスしてもらうには
hiki-dev:360(リンク切れ?)とか、おまぬけ活動日誌 とかで展開されてた話。
今回必要があって探したので、まとめておきます。プラグインと Apache が前提です。
Hiki側をいぢる
プラグインでもって、ページ上のリンクを hoge.htmlにする必要があります。
def hiki_anchor( page, text )
if page == 'FrontPage' then
make_anchor('.', text)
else
make_anchor("#{CGI::escape(page)}.html", text)
end
end
この内容を z.rb とでも名前をつけて、Hiki の plugin ディレクトリに作ります。(00default.rb よりも後で読まれて同名メソッドを overrideする必要があるから)
Apache側での設定
mod_rewrite の設定をします。mod_rewrite とは Apacheのモジュールで、ルールを書くことでリクエストされた URLをいじることが出来ます。今回ならば hoge.html というリクエストを hiki.cgi?hoge に変換する訳です。
apache の設定ファイル(httpd.conf)で以下のように設定します。 ここで、「/」が含まれるページ名のために AllowEncodedSlashes ディレクティブ を有効にする必要がありますのでご注意ください。
AllowEncodedSlashes On
<Directory "/var/www/hoge/hiki/">
RewriteEngine on
RewriteRule ^(.+)\.html hiki.cgi?$1 [L]
</Directory>
なお、mod_rewrite を利用する場合は、FollowSymLinks オプションも必要です。
プラグイン修正
- misc/plugin/google-sitemaps.rbを修正
- 18行目、?#{name.escape}→#{name.escape}.html
- misc/plugin/footnote.rbを修正
- 41行目、#{@footnote_url % @footnote_index[0]}→\##{@footnote_name % @footnote_index[0]}
- 73行目、#{@footnote_mark_url % fn[0]}→\##{@footnote_mark_name % fn[0]}
参考リンク
- Apache URL Rewriting Guide
- http://japache.infoscience.co.jp/rewriteguide/
- htmlでアクセスしたい@tdiary-users
- http://tdiary-users.sourceforge.jp/cgi-bin/wiki.cgi?html%A4%C7%A5%A2%A5%AF%A5%BB%A5%B9%A4%B7%A4%BF%A4%A4
別のwikiですが、PATH_INFOを使う方法もあるようです。 http://www.hyuki.com/kakera/20040425212933.html
Keyword(s):
References: