星期四, 五月 01, 2008

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

當看到一卡車的檔案, 每個檔案都要進去裡面加個 include 或某些資料, 想到就很辛苦~

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

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

php_value auto_prepend_file / auto_append_file 設定

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

其它常用設定

  • DirectoryIndex index.html index.htm index.php # 此目錄下如果沒輸入檔名, 預設搜尋順序
  • AddType application/x-httpd-php .html .htm # 讓 .html .htm 都經過 php parser
  • php_value default_charset utf-8 # 預設編碼吐 UTF-8
相關標籤

this is comment icon [回覆]

這個 tip 很實用, 謝啦

Comment by pank (05/03/2008 00:39)

this is comment icon 回 pank [回覆]

嗯嗯~ 要在每頁加入某段 js, 發現他頁面沒有切 footer 或 header 就會想用這招.. XD

Comment by Tsung (05/03/2008 08:27)
Add this page to del.icio.us Add this page to Yahoo Taiwan's bookmark Add this page to MyShare

發表迴響

標題

內容 (限制 1000 字)

暱稱

電子郵件

個人網頁


 authimage


PS: 若無法留言, 請先確認是否有打開 JavaScript, 造成您的困擾, 實在萬分對不起 Orz...(如果無法留言, 勞煩可以發信給我好嗎? 謝謝.)
PS2: 若您的留言被誤判, 我都會再自行看過, 不需要一直重覆張貼~