htmlファイルにinclude

NO IMAGE

htmlファイルに別のファイルをincludeしたいときの方法を
簡単にまとめてみました。
1.phpのinclude
2.SSIでinclude
3.それ以外だと。。。

1.phpのinclude
・htmlファイル
<?php include(dirname(__FILE__).'foobar.html'); ?>

・htaccess
AddType application/x-httpd-php .html
ただし、サーバによっては下記のようになる場合もあるので
サーバのマニュアルとかFAQで確認し、設定すること。
AddHandler application/x-httpd-php .htm
AddType application/x-httpd-php5 .html
AddType application/x-httpd-php5.2 .html
などなど。。

2.SSIでinclude
・html
<!--#include virtual="foobar.html"-->

・htaccess
Options -Indexes +Includes
AddType text/x-server-parsed-html .html

※これもサーバによるので確認すること。

3.上記1も2も使えなかったら
・iframe使う
・javascript(ajax)を使う
などの方法も考えられる。

IT関係カテゴリの最新記事