<-
Apache > HTTP Server > Documentation > Version 2.4 > How-To / Tutorials

Hġ 丮: Server Side Includes Ұ

݋b _ _ Ɯ”. ٿ ~@ ݋ O[.

Server-side includes ȝ~[ HTML ݋ ~@ ߰ ] .

Support Apache!

O

top

Ұ

ۻ@ SSIO θb Server Side Includes Ѵ. SSI ɸ[nU ݋L r[b Ҏ^ HTML ~@ ߰[b ⺻ SSI ȝ~^@ ҰѴ.

κл@ SSI C 얰 @ Oޱ^@ Ѵ.

top

SSI ΰ?

SSI (Server Side Includes)b HTML ȝ~[b C, ݋zV ݋L QѴ. SSI ȝ~[R CGI α׷Ƴ ٸ v ü 齁݋ ݋z[ ʽOn HTML ڷ e ~@ ߰ ] .

SSI ȝ~ ”R α׷ڷ ü e r@ ݋ r κГ @ ݋z V rn ٳC ؾ ޷ȴ. SSIb C @ r ߰[b . ׵\ ݋zV κ@ eؾ ѴٔR ٸ Ҏ^@ ãƺ Ѵ.

top

SSI ɸ[nU ݋L r[

݋L SSI Q[R apache2.conf HϓƳ .htaccess HϿ݋ ٞ C ȝ~ؾ Ѵ.

Options +Includes

׵\R Hġb HϿ݋ SSI C QѴ. rb \ Options C O, C@ ݋ Y݋ ȿ . E݋ C w Q[ SSI [b Ưr 丮݋ Options ȝ~Ѵ.

HϿ݋ SSI C Q[b ͻ@ ”. Hġ H@ Q ˷ Ѵ. ΰ Ҏ^ . [b ٞ @ C .shtml @ Ưr H Ȯڸ H@ Q[b Ҏ^ƴ.

AddType text/html .shtml
AddOutputFilter INCLUDES .shtml

Ҏ^ Z@ ƹ b SSI C ߰[b SSI C Q[ .shtml Ȯڸ ο[V얿 Hϸ r ؾ [b ƴ.

ٸ Ҏ^@ XBitHack C ȝ~[b Ҏ^ƴ.

XBitHack on

XBitHackb ѓ b HϿ݋ SSI C QѴ. E݋ ƹ b SSI C ߰ѴٔR Hϸ@ [ ʽO chmod HϿ @ ֔R ȴ.

chmod +x pagename.html

[ ƾ [. U .shtml Hϸ ġ O .html H@ SSI Q[O O[b ȝ . ȝ@ Ƹn XBitHack 𸣾b . U @ Ʒ [R Hġb HϿ SSI C ^n Ŭƾh b H@ Ѵپb ͓ƴ. ɓ ſ ] ڸ, @ e ”.

Un݋b ѓƶ ͓ ^V얿 ڸ ȝ~ ] ^.

~ ƿ݋ [ ƱV얿 Hġ ⺻ r@ SSI ]rϰ content length HTTP c ʾb. E݋ ݋ ij{[ o[O Ŭƾh Lb ɓ . ΰ ذҎ^ .

  1. XBitHack Full r@ ȝ~Ѵ. ׵\R Hġb `[b(include) Hϵ ]rϻ@ Cü E ] H Ǹ O ]r@ ˾Ƴ.
  2. mod_expires b C ȝ~[ HϿ @ r[R v UC ݋ ij{ ] .
top

⺻ SSI C

SSI C ȝ~^@ ٞ .

<!--#element attribute=value attribute=value ... -->

HTML ּ eV얿 SSI @ [ ʾƙn HTML zb vb CѴ. SSI ùٷ r[R C @ڷ ٲ۴.

elementb ٞ [. ٞ ȸ ڼ ͓ƴ. ݻ@ SSI ] b  δ

<!--#echo var="DATE_LOCAL" -->

echo elementb ]@@ ״ Ѵ. CGI α׷ [b ȯ溯] ܿn \ F ] . , set element ȝ~[ ] r ]n .

e ʾbٔR, ٞ config element timefmt attribute ȝ~Ѵ.

<!--#config timefmt="%A %B %d, %Y" -->
Today is <!--#echo var="DATE_LOCAL" -->

H ]r

݋b <!--#flastmod file="index.html" --> ڷ ]rǾ

elementn timefmt e r ޷ȴ.

CGI α׷ `[

^ SSI ȝ~^ [, Ƶ փ~[b ``Ҏ] ī'' @ CGI α׷ Ѵ.

<!--#include virtual="/cgi-bin/counter.pl" -->

top

߰

ٞ@ HTML ݋ ȝ~ ] b  SSI .

݋ ڷ ]rǾ?

տ݋ SSI ȝ~[ ȝ~ڿ ݋ ]r@ ˸ ] ٽO ߴ. ׵\ Ҏ^@ ˷ ʾҴ. ٞ ȵ带 HTML ݋ ȝ~[R C U@ ׃. ݋ Ѵ SSI ùٷ ۵ؾ Ѵ.

<!--#config timefmt="%A %B %d, %Y" -->
݋b <!--#flastmod file="ssi.shtml" --> ڷ ]rǾ;

ssi.shtml_ [b Hϸ@ ȝ~Ѵ. ƹ n ٿ@ ] b ~ȵ带 ѴٔR, Hϸ _ LAST_MODIFIED ] ȝ~Ѵ.

<!--#config timefmt="%D" -->
This file last modified <!--#echo var="LAST_MODIFIED" -->

timefmt e ڼ rb ˵݋ strftime@ ãƺ. ^@ .

F [Z@ `[

\ b ȝh ѴٔR ü ]r[b ͻ@, Ư F ܰ@ nU ]r[b ͻ@ r UӴ.

Z(header) [Z(footer)@ HϷ `[ Ʒ ]r δ@ ] . ݋ include SSI w ȝ~[ [Z H [ `[R ȴ. include element file attribute virtual attribute ` H@ rѴ. file attributeb Hϰδ. , (/ C۸[b) Hϰγ ȿ ../ ȝ~ ] ^. Ƹn ݋z[b ݋ URL@ r ] b virtual attribute Ϟ~ ͓ƴ. θ / C ] , `[b Hϓ ݋z[b Hϰ @ ݋L Ѵ.

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

b ΰ J݋ ` [Z HϿ LAST_MODIFIED C ־b. `[b HϿn SSI C ] ڸ, Ʒ ` Hϓ ٸ H@ `[b eڷ \ ` ]n .

top

ƿܿ r ] b ͻ@?

C e config(r) ܿ ΰ config(r) ] .

SSI C ߽oǔR ٞ @ 얂䰡 ´

[an error occurred while processing this directive]

얂並 [O ʹٔR config element errmsg attribute ȝ~[ Ѵ.

<!--#config errmsg="[It appears that you don't know how to use SSI]" -->

ȝh ݋z[ SSI C ذ[ ȝ~ڰ Ʒ 얂並 ʱ ٶ. (׷?)

׸O sizefmt attribute ^ȯ[b Hr e@ config(r) ] . ٓh r⸦ ַR bytes, Kb Mb r⸦ ַR abbrev ȝ~Ѵ.

top

w [

b ٞ ޿ ۻ@ CGI α׷ SSI ȝ~[b @ R rƴ. ݻ@ exec element ] b ٸ ͵@ ͓ƴ. SSIb @ (rȮb /bin/sh Win32 ȝ~ѴٔR DOS ) ȝ~[ w Ѵ. 齁, ٞ@ 丮 U@ ش.

<pre>
<!--#exec cmd="ls" -->
</pre>

or, on Windows

<pre>
<!--#exec cmd="dir" -->
</pre>

dir ¿ v ȥ ``<dir>'' ڄP `ǘV얿, Un݋ C ȝ~[R ƻ ͓ƴ.

ɻ@ exec ±׿ ȝ~ wn ] V얿 ſ [. ``ҎU'' ȝ~ڰ ~@ ]r ] b ȯƶR, @ ȝ~ؼ ȵȴ. Options C IncludesNOEXEC ƱԄh ȝ~[ SSI A~[ exec @ @ ] .

top

O SSI ^

~@ ¸[b ܿ Hġ SSIb ] r ɸ[O, 얰 얿 ] ȝ~ ] .

O

ۿ݋ [b κ ɻ@ Hġ 1.2 ȝ~ ] . , Hġ 1.2 ƻ@ ȝ~[ ʾbٔR Ƹn EƵؾ Ѵ. ض. ض. ٸ ͓ƴ.

] r

set C ȝ~[ ߿ ȝ~ ] r ] . ՙڷ ] ʿ[V얿 v Ѵ. ^@ ٞ .

<!--#set var="name" value="Rich" -->

ٞ @@ ڱ״ r[ ʽO ȯ溯] ݋ ]( 齁, LAST_MODIFIED) ٸ ] ȝ~[ ]@@ r ]n . V ] տ ޵\ FC($) ٿ݋ ڄP Ƈ ]@ FCѴ.

<!--#set var="modified" value="$LAST_MODIFIED" -->

]@ ޵\ ڸ ״ ¸[R ޵\ FC տ wE{ ȝ~Ѵ.

<!--#set var="cost" value="\$100" -->

ڷ ׃ ڄP ߰ ] ȝ~[b ڿ b ڙn ]ڷ θ[ ȥǾb , ]@ x ݋ ȮǞ Ѵ. (@ ã , ظ[ ٶ.)

<!--#set var="date" value="${DATE_LOCAL}_${DATE_GMT}" -->

Fe

] r[O ] ” 얓 ɸ[. SSI v Z αE־𽁰 ȴ. mod_includeb @ b if, elif, else, endif 䟒 Ѵ. \ ] .

䟒b ٞ .

<!--#if expr="test_condition" -->
<!--#elif expr="test_condition" -->
<!--#else -->
<!--#endif -->

test_conditionb 񱳶n ȝ~ ] . @@ ٸ @ 񱳸[ų, Ưr @ ``'' ȝѴ. (ڄP 񽁘 ʙڔR ƴ.) ȝ~ ڸ R, mod_include ݋ O[. ٞ@ @ ȝ~  .

rHϿ ٞ R@ ߰Ѵ.

BrowserMatchNoCase macintosh Mac
BrowserMatchNoCase MSIE InternetExplorer

Ŭƾh }ŲC݋ [b Internet ExplorerR ȯ溯] ``Mac'' ``InternetExplorer'' ڷ rѴ.

׸O SSI ݋ ٞ b.

<!--#if expr="${Mac} && ${InternetExplorer}" -->
⿡ ȝ얰 ´
<!--#else -->
⿡ JavaScript ȵ尡 ´
<!--#endif -->

ŲC IE ^} b ͻ@ ”. b Z vֿ ٸ ^݋b ^b JavaScript ȵ尡 ŲC IE݋b ۸[ ʾ݋ C@ Oeߴ. b ӳC ذåƴ.

( rǸ[ ^ ȯ溯]ư) ]n 얿 ȝ~ ] . ƶġb SetEnvIf ٸ L C ȯ溯] r ] V얿 CGI ^ƙn ~@ ] .

top

SSIb ȮǞ CGI e[b ٸ v@ ü ] ^. ׵\ @ ߰ E^ ~@ ߰[⿡b Ǹ Ҏ^ƴ.

:  en  |  es  |  fr  |  ja  |  ko 

top

Comments

Notice:
This is not a Q&A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed again by our moderators if they are either implemented or considered invalid/off-topic. Questions on how to manage the Apache HTTP Server should be directed at either our IRC channel, #httpd, on Freenode, or sent to our mailing lists.
С͸