2016年3月10日 星期四

Apache 開啟支援 SSI 功能

幫忙起一個我完全不熟悉的 Web Site 在 Apache 上,副檔名是 shtml,而且 shtml 裡面夾帶很多 <!--#include file="/XXX/XXX" --> 的這種格式,而我去 google 這種 include 的方式要讓 Apache 讀得懂,要開啟 SSI (Server Side Includes) 以及開啟 Include 。

主要的做法,請參考 http://httpd.apache.org/docs/current/howto/ssi.html,其實寫得很清楚~

而且, <!--#include file="" --> 好像不是 apache server 在看的格式,好像是 IIS 系列的 server,我後來發現 apache 根本看不懂 include file 這個詞,還要把 file 都換成 virtual 這個單字才行,否則爬出來會得到 [an error occurred while processing this directive] 這樣的錯誤訊息。 (如果有人知道怎麼讓 apache 也看得懂 file 這個詞來做 include 請跟我說 Orz 謝謝你!但前提是不改動 include 這個單字)

首先先讓你的 apache 啟用 Include, rewrite 的功能(rewrite 要不要我忘記了.)

1. apache 要開啟 include 的功能
a2enmod include

2. apache 要開啟 rewrite 的功能
a2enmod rewrite
記得重啟 apache。


接著 apache 修改的部分,修改 httpd.conf,在 Options 的地方加上 Includes。像是:
<Directory /var/www/>
        Options Indexes FollowSymLinks Includes
        AllowOverride All
        Require all granted
</Directory>
或是你只把 AllowOverride All 打開,然後在專案目錄下透過 .htaccess 來複寫也可以。如果你是想用 .htaccess:

.htaccess
Options Includes
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
AddOutputFilters 加入 .shtml 表示只要付檔名是 shtml 就先經過 Inludes 的過濾,假如你的  <!--#include virtual ="" -->  是寫在副檔名是 php 的檔案情況下,則 AddOutputFilter INCLUDES .php .shtml,只要再加上 .php 就行。


就這樣,我 try 了好久,發現雷踩在根本忘記 a2enmod include 開啟 apache  的 include 模組。當初還以為 php -S 的方式就可以讀這種 include 的方式... 結果路要繞道用 apache 的方式去看, IIS 我又不熟 ... 不過好險,至少可以看到畫面了 :P

沒有留言:

張貼留言

若你看的文章,時間太久遠的問題就別問了,因為我應該也忘了... XD

Vue multiselect set autofocus and tinymce set autofocus

要在畫面一進來 focus multiselect 的方式: 參考: https://jsfiddle.net/shentao/mnphdt2g/ 主要就是在 multiselect 的 tag 加上 ref (例如: my_multiselect), 另外在 mounted...