使用SSI(Server Side Include)的html文件擴展名,SSI(Server Side Include),通常稱為"服務器端嵌入"或者叫"服務器端包含",是一種類似于ASP的基于服務器的網頁制作技術。默認擴展名是 .stm、.shtm 和 .shtml。
什么是SSI?
SSI是英文Server Side Includes的縮寫,翻譯成中文就是服務器端包含的意思。從技術角度上說,SSI就是在HTML文件中,可以通過注釋行調用的命令或指針。SSI具有 強大的功能,只要使用一條簡單的SSI命令就可以實現整個網站的內容更新,時間和日期的動態顯示,以及執行shell和CGI腳本程序等復雜的功能。 網站維護常常碰到的一個問題是,網站的結構已經固定,卻為了更新一點內容而不得不重做一大批網頁。SSI提供了一種簡單、有效的方法來解決這一問題,它將 一個網站的基本結構放在幾個簡單的HTML文件中(模板),以后我們要做的只是將文本傳到服務器,讓程序按照模板自動生成網頁,從而使管理大型網站變得容易。
實現方法
建立頭文件
head.html
1 2 3 4 5 6 7 8 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> < html > < head > < title >Untitled Document</ title > < meta http-equiv = "Content-Type" content = "text/html; charset=gb2312" > </ head >< body > < div style = "background-color:#00CC66;boder:1px groove orange " >這是頭</ div > |
foot.html
這是尾
</body></html>
連接頭和尾
linuxtone.shtml
1 2 3 4 5 | <!--#include file="head.html"--> < hr > < b >頭尾文件內容都顯示。表示SSI工作正常。shtml顯示正常</ b > < hr > <!--#include file="foot.html"--> |
配置文件很簡單。
apache配置如下:
修改如下幾處
1 2 3 | AddType text/html .shtml AddOutputFilter INCLUDES .shtml Options Indexes FollowSymLinks includes |
includes 為追加
你要是感覺麻煩可以用以下命令替換。
1 2 3 | sed -i 's##AddType text/html .shtml#AddType text/html .shtml#' /usr/local/apachefile/httpd.conf sed -i 's##AddOutputFilter INCLUDES .shtml#AddOutputFilter INCLUDES .shtml#' /usr/local/apachefile/httpd.conf sed -i 's#Options Indexes FollowSymLinks#Options Indexes FollowSymLinks includes #' /usr/local/apachefile/httpd.conf |
shtml 的壓縮方法不同于js css php
方法如下:
AddOutputFilter INCLUDES;DEFLATE shtml
新聞熱點
疑難解答