2010年1月3日 星期日

Apache2 開啟 .htaccess 功能 & CodeIgniter 移除 index.php

1.一般都是使用.htaccess但是可以設定要依照別的檔案名稱

/etc/apache2/apache2.conf

內的

AccessFileName .htaccess


2.在httpd.conf可以設定要作用的路徑


Options FollowSymLinks
AllowOverride All


/var/www/admin
就是要作用的資料夾

3.載入mod_rewrite以啟用RewriteEngine模組
sudo a2enmod rewrite

4.設定完重開apache2
sudo /etc/init.d/apache2 restart

5.在資料夾放入.htaccess檔案
設定轉換路徑
EX:
RewriteEngine On
RewriteBase /admin
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

上面的/admin對應之前的/var/www/admin

不過他是網路上的第一層資料夾
ex:http://localhost/admin

將.htaccess放到/var/www/admin/

下就好了

以下給CodeIgniter使用
=======================================
如果要把網址後面的index.php取消
上面的步驟照作之外

下面在設定一些東西
config.php

$config['index_page'] = "";
$config['uri_protocol'] = "REQUEST_URI";

大概就這樣吧....