CI .htaccess for HiHosting主機

列印

本文轉自http://codeigniter.org.tw/forum/viewtopic.php?f=7&t=3900

 


近期把專案程式 (PHP+CI) 交付到客戶承租的 中華電信HiHosting 主機時,

發現 .htaccess 檔案的關係,導致網頁一直未能正常顯示出來 ( 403 Forbidden Error ),

拜求咕狗大神之後,只要在我們原有的.htaccess 檔多加入 Options +FollowSymLinks 就可以了 ;

後來不經意又看到 SymLinksIfOwnerMatchFollowSymLinks 更安全,但效能也許差一些些,

所以再將之修正為 Options -FollowSymLinks +SymLinksIfOwnerMatch

修正過後的 .htaccess 檔如底下所示:

 

代碼:
# -CodeIgniter- TO REMOVE index.php FROM URL
Options -FollowSymLinks +SymLinksIfOwnerMatch
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]   


總言之,對我手上兩個專案客戶都採用HiNet HiHosting 主機時,須使用上方的 .htaccess 網站才能正常運作;

以上,野人獻曝,若有誤導或者更優的 solution 也請板上前輩們不吝指教,謝謝。


## 參考資料如下 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

◎ 底下摘錄自 Apache ( http://jendo.org/files/doc/apache.html )

代碼:
二、路徑的 Options

Options 的參數,可在參數前加上「+」或「-」。Options屬性如果沒有用「+」或者「-」來增加或者減少一個功能的時候,每個之前定義的Options的所有功能都會被取消,直到你又為它指定一些功能。
且options屬性在整體設定和虛擬主機設定上並不相關,互相不起作用,因為他們在各自的範圍內被重載了。
所以如果要在虛擬主機裡面使用在整體設定中的Options功能,那麼就不要在虛擬主機設定中指定Options功能;而是用「+」或者「-」符號來增加或者減少功能。

Options的諸參數如下:
All: 以下諸功能皆有。
None: 以下諸功能皆無。
Indexes: 自動產生目錄的索引,將Indexes拿掉,點選連結目錄就不會秀出目錄來,會改成403 forbidden的訊息頁面。
Includes: 提供 SSI (Server-Side Inclues) 功能,即使用Apache的指令在html檔中寫程式。須先載入 includes_module 。詳見 http://home.educities.edu.tw/shirock/comp/Apache_SSI.htm 。
FollowSymLinks: 遵循符號鏈接,即能夠連到其它的目錄去執行。會壓過SymLinksIfOwnerMatch。
SymLinksIfOwnerMatch: 對符號鏈接及其每一層父資料夾,都進行權限檢查,當連結檔本身的owner跟連結目的地的owner不同時拒絕存取。
ExecCGI:可以執行CGI程式。
MultiViews: 送出多國語言支援的頁面。此功能必須被明確指定,Options All並不會提供這個功能。




◎ 底下摘錄自 Apache Performance Tuning ( http://httpd.apache.org/docs/2.2/misc/perf-tuning.html )

代碼:
FollowSymLinks and SymLinksIfOwnerMatch
Wherever in your URL-space you do not have an Options FollowSymLinks, or you do have an Options SymLinksIfOwnerMatch
Apache will have to issue extra system calls to check up on symlinks. One extra call per filename component. For example,
if you had:

DocumentRoot /www/htdocs
<Directory />
Options SymLinksIfOwnerMatch
</Directory>

and a request is made for the URI /index.html. Then Apache will perform lstat(2) on /www, /www/htdocs, and /www/htdocs/index.html.
The results of these lstats are never cached, so they will occur on every single request.
If you really desire the symlinks security checking you can do something like this:

DocumentRoot /www/htdocs
<Directory />
Options FollowSymLinks
</Directory>

<Directory /www/htdocs>
Options -FollowSymLinks +SymLinksIfOwnerMatch
</Directory>

This at least avoids the extra checks for the DocumentRoot path. Note that you'll need to add similar sections if you have any Alias
or RewriteRule paths outside of your document root. For highest performance, and no symlink protection,
set FollowSymLinks everywhere, and never set SymLinksIfOwnerMatch.