LoginSignup
26
31

More than 5 years have passed since last update.

xamppでinclude(SSI)を使う

Last updated at Posted at 2014-07-28

SSIとは

SSI : server side include

共通部分(例えばヘッダー・フッター・サイドナビ等)がある場合、全てのソースにコピペするのは面倒です。
更新があった場合全てのファイルのその部分を書き換えないといけません。
一つのhtmlファイルに更新をかけるだけで反映されるのが効率的です。
SSIを使うとそれが可能になります。

私includeと聞いて最初勘違いしておりましたが、
PHPのinclude文ではありません。SSIのincludeです。

html上書き方

html上に

<!--#include virtual="resource/include/header.html" -->

と、書いてあったら、それです。
virtualのかわりに、fileと書くこともあって、
virtual ⇒ ドキュメントルートからのパス。別ディレクトリでもサーバの絶対パスでも指定が可能

EX)
○ ⇒ virtual="resource/include/header.html"
○ ⇒ virtual="include/header.html"  

file ⇒ 同ディレクトリやサブフォルダにある場合のみ。
上層のディレクトリにあるファイルは読み込めません。

EX)
× ⇒ file="resource/include/header.html"  
○ ⇒ file="include/header.html"        
○ ⇒ file="header.html"              

SSIを使ったファイルをローカルで確認するには

ローカルでSSIを利用するには、Apacheのhttpd.confファイルを編集する必要があります。
私がxamppを使用しているため、xamppで失礼いたします。

C:\xampp\apache\conf\httpd.conf

414行目あたりに

    # To parse .shtml files for server-side includes (SSI):
    # (You will also need to add "Includes" to the "Options" directive.)

と書いてあるところを見つけ、その下の

417行目あたりを

AddType text/html .shtml
AddOutputFilter INCLUDES .shtml

AddType text/html .shtml .html
AddOutputFilter INCLUDES .shtml .html

に変更する

そしてapacheを再起動すると大丈夫です。

.htaccessなら

#AddType text/html .html .htm .shtml
#AddOutputFilter INCLUDES .html .htm .shtml

同様、.htmlを足しとけばいいようです。

26
31
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
26
31