mod_layout 可在 HTTP 回應的文件頭部、尾部或指定標籤前後動態插入內容。典型應用:
| Apache 版本 | mod_layout 版本 |
|---|---|
| 1.3 | 3.1 |
| 2.0 | 4.1 |
| 2.2 | 5.1 |
下載位址:https://download.tangent.org/
# 1. 下載解壓
wget https://download.tangent.org/mod_layout-5.1.tar.gz
tar xvfz mod_layout-5.1.tar.gz
cd mod_layout-5.1
# 2. 編輯 Makefile,確認路徑
APXS=apxs
APACHECTL=apachectl
CC=`apxs -q CC`
INC=-I`apxs -q INCLUDEDIR` `$(APXS) -q CFLAGS`
LD_SHLIB=`apxs -q LDFLAGS_SHLIB`
# 關鍵:確保 APXS 與 APACHECTL 指向正確
# 3. 編譯安裝
make
make install
<VirtualHost *:80>
<Directory /home/foo/public_html>
AllowOverride None
Options SymLinksIfOwnerMatch
AddOutputFilter LAYOUT html
LayoutFooter /menu.html
LayoutIgnoreURI /diary/*
LayoutIgnoreURI /linux/*
</Directory>
</VirtualHost>
AddOutputFilter LAYOUT html:啟用對 html 的處理,可追加 php、shtml 等LayoutFooter /menu.html:在文件尾插入指定檔案內容LayoutIgnoreURI:排除不需處理的 URI 路徑若網頁已啟用 gzip 壓縮,mod_layout 將無法正常運作。 需在壓縮前插入內容,或針對特定類型關閉壓縮。生產環境建議配合 mod_deflate 的 SetOutputFilter 順序調整,或使用 mod_substitute 替代方案。
完整指令文件:官方手冊