http://example.com/hoge.html
http://example.com/foo/bar.html
というアクセスをそれぞれ
http://example.com/index.php?page=hoge.html
http://example.com/index.php?page=foo/bar.html
と内部的に処理したい。
ブラウザの表示は
http://example.com/hoge.html
http://example.com/foo/bar.html
のままにしてください。
.htaccessを「http://example.com/」ルート直下に設置する場合の記述です。
「hoge.html」と「foo/bar.html」だけを書き換えたい場合は、以下のように記述します。
RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^hoge.html$ index.php?page=hoge.html [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^foo/bar.html$ index.php?page=foo/bar.html [L]
例示したHTMLファイルだけでなく、まとめて書き換えたい場合は、以下のように記述します。
RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([A-z0-9/._-]+\.html)$ index.php?page=$1 [L]
※「RewriteCond」行で、ファイルやフォルダが実在する場合は、書き換えないという条件を追加しています。
http://memorva.jp/memo/linux/mod_rewrite.php
※不明な点がある場合は、コメント欄を開けておいてくださると、今後のフォローがしやすいです。
ありがとうございました。