ci框架去除index.php的方法:首先打開apache的配置文件并修改;然后在CI的根目錄下建立“.htaccess”;接著修改內容為“RewriteRule ^(.*)$ /CI/index.php/$1 [L]”;最后重啟即可。
推薦:《PHP視頻教程》
去掉CodeIgniter(CI)默認url中的index.php的步驟:
1.打開apache的配置文件,conf/httpd.conf :
LoadModule rewrite_module modules/mod_rewrite.so
把該行前的#去掉。
搜索 AllowOverride None(配置文件中有多處),看注釋信息,將相關.htaccess的該行信息改為:
AllowOverride All
2.在CI的根目錄下,即在index.php,system的同級目錄下,建立.htaccess,直接建立該文件名的不會成功,可以先建立記事本文件,另存為該名的文件即可。內容如下(CI手冊上也有介紹):
RewriteEngine on RewriteCond $1 !^(index.php|images|robots.txt) RewriteRule ^(.*)$ /index.php/$1 [L]
如果文件不是在www的根目錄下,例如我的是:
http://localhost/ci_demo_1/index.php/
第三行需要改寫為
RewriteRule ^(.*)$ /CI/index.php/$1 [L]
另外,我的index.php的同級目錄下還有assets文件夾,這些需要過濾除去,第二行需要改寫為:
RewriteCond $1 !^(index.php|images|<span style="text-decoration: underline;">assets</span>|robots.txt
3.將CI中配置文件(application/config/config.php)中
$config['index_page'] = "index.php";
改成
$config['index_page'] = "";
重啟apache,完成。
php 框架ci去index.php的方法
網上有很多方法都要引入.htaccess文件,如果是在測試環境下,動態和靜態的文件放到一塊,可能測試會有一定的問題(由于全部定向到index.php),靜態網頁訪問不了。
這里提供一種方法,只需要修改http.conf文件,
步驟:
1 :在配置虛擬目錄下加入
<Directory /> Options Indexes FollowSymLinks AllowOverride all Order allow,deny Allow from all </Directory> <IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^/script/(.*) /script/$1 [L] RewriteRule ^(.*)$ /index.php?/$1 [L] </IfModule>
2 將下面這行前面的;去掉
LoadModule rewrite_module modules/mod_rewrite.so
3 重啟apache就可以了,無需加入.htaccess文件