goTOP
October 22, 2011

使用 htaccess 快速於網頁 Header/Footer 插入特定程式

| |
伺服器架設 心得 » Apache | 閱覽(3973) | Posted by apao at 09:28
當看到一卡車的檔案, 每個檔案都要進去裡面加個 include 或某些資料, 想到就很辛苦~

另一種做法就是用 .htaccess 並用 php 的功能, 就可以快速達到這點~

.htaccess 是對整個目錄以下的做動作, 所以下述參數會對此目錄的所有檔案都加上 header.php

php_value auto_prepend_file / auto_append_file 設定

# 在每個檔案的最上方(前方), 都把 header.php 的內容插入
php_value auto_prepend_file "header.php"

點擊在新視窗中瀏覽此圖片

範例:
http://apao.zapto.org/~apao/Apache/addheader/index.php

說明:

上方
php_value auto_prepend_file "header.inc"
方式強制夾進index.php html碼的上方。

中間

原本的body部份

下方
<?php include("footer.php"); ?>
方式,將[footer.php]置入index.php

本地登入下載[htaccess.txt]
htaccess檔案
下載相關檔案
這個檔案只能在登入之後下載。請先 註冊登入

php_value auto_prepend_file "header.php"

本地登入完整下載 [addheader.zip]
下載相關檔案
這個檔案只能在登入之後下載。請先 註冊登入


在DSM舊版本中是支援這樣的寫法 現在Synolgoy DSM 5.1-5022 這種寫法無法動作
點擊在新視窗中瀏覽此圖片



於是我又參考一下國外的寫法看看

header.php 檔案連結
http://apao.zapto.org/~apao/Apache/addfooter/header.php

footer 檔案連結
http://apao.zapto.org/~apao/Apache/addfooter/footer.php

# 在每個檔案的最下方(後方), 都把 footer.php 的內容插入
php_value auto_append_file "/home/www/Apache/addfooter/footer.php"

檔案夾檔案下載:
下載相關檔案
這個檔案只能在登入之後下載。請先 註冊登入


參考網站 對方寫法:
PHPで翻訳三昧
http://beatnik.jp/blog/archives/249
php_value auto_prepend_file "/home/userdir/spamFilter.php"

ハチログ
參考網站 對方寫法:
http://www.hachi-log.com/prepend-append/
php_value auto_prepend_file /dir/dir/file-prepend.php

php.ini 檔案 需要另外加入...
#auto_prepend_file メインファイルの前に実行する
auto_prepend_file = /dir/dir/file-prepend.php

#auto_append_file メインファイルの後に実行する
auto_append_file = /dir/dir/file-append.php

找了Apache官網
http://httpd.apache.org/docs/2.4/ja/

Google搜尋結果似乎沒有針對這無法執行做說明或是追申敘述的內容
Search: apache 2.4 auto_append_file

在Synology官網上的資料
https://www.synology.com/zh-tw/knowledgebase/faq/310
DSM 版本   PHP   MySQL/MariaDB   Apache
DSM 5.0   5.5   5.5                   2.2(Unix)
DSM 4.3   5.3.28   5.1.49   2.2(Unix)
Facebook twitter LINEk
文章来自: 本站原創
0 Comment(s)
我要發表評論
暱稱
密碼 [ 訪客無需密碼 ]
電郵
網址
開啟HTML 開啟UBB 開啟表情 隱藏 記住我