解析如何去掉CodeIgniter URL中的index.php
更新時間:2013年06月25日 17:44:22 作者:
本篇文章是對如何去掉CodeIgniter URL中index.php的方法進行了詳細的分析介紹,需要的朋友參考下
CI默認的rewrite url中是類似這樣的,例如你的CI根目錄是在/CodeIgniter/下,你的下面的二級url就類似這樣http://localhost/CodeIgniter/index.php/welcome。不太好看,怎么把其中的index.php取掉呢?
1. 打開apache的配置文件,conf/httpd.conf :
LoadModule rewrite_module modules/mod_rewrite.so,把該行前的#去掉。
搜索 AllowOverride None(配置文件中有多處),看注釋信息,將相關(guān).htaccess的該行信息改為AllowOverride All。
2. 在CI的根目錄下,即在index.php,system的同級目錄下,建立.htaccess,直接建立該文件名的不會成功,可以先建立記事本文件,另存為該名的文件即可。內(nèi)容如下(CI手冊上也有介紹):
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
如果文件不是在www的根目錄下,例如我的是:http://www.nowamagic.net/CodeIgniter/,第三行需要改寫為RewriteRule ^(.*)$ /CodeIgniter/index.php/$1 [L]。
另外,我的index.php的同級目錄下還有js文件夾和css文件夾,這些需要過濾除去,第二行需要改寫為:RewriteCond $1 !^(index\.php|images|js|css|robots\.txt)
3.將CI中配置文件(system/application/config/config.php)中$config['index_page'] = "index.php";將$config['index_page'] = ""; 。
/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
*/
$config['index_page'] = '';
重啟apache
1. 打開apache的配置文件,conf/httpd.conf :
LoadModule rewrite_module modules/mod_rewrite.so,把該行前的#去掉。
搜索 AllowOverride None(配置文件中有多處),看注釋信息,將相關(guān).htaccess的該行信息改為AllowOverride All。
2. 在CI的根目錄下,即在index.php,system的同級目錄下,建立.htaccess,直接建立該文件名的不會成功,可以先建立記事本文件,另存為該名的文件即可。內(nèi)容如下(CI手冊上也有介紹):
復(fù)制代碼 代碼如下:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
如果文件不是在www的根目錄下,例如我的是:http://www.nowamagic.net/CodeIgniter/,第三行需要改寫為RewriteRule ^(.*)$ /CodeIgniter/index.php/$1 [L]。
另外,我的index.php的同級目錄下還有js文件夾和css文件夾,這些需要過濾除去,第二行需要改寫為:RewriteCond $1 !^(index\.php|images|js|css|robots\.txt)
3.將CI中配置文件(system/application/config/config.php)中$config['index_page'] = "index.php";將$config['index_page'] = ""; 。
復(fù)制代碼 代碼如下:
/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
*/
$config['index_page'] = '';
重啟apache
相關(guān)文章
同臺服務(wù)器使用緩存APC效率高于Memcached的演示代碼
之前看到有文章說同臺服務(wù)器上APC的效率是Memcached的7倍,APC效率比Memcached高是肯定的,至于倒底快多少,我寫了個小程序測試了下。2010-02-02PHP實現(xiàn)XML與數(shù)據(jù)格式進行轉(zhuǎn)換類實例
這篇文章主要介紹了PHP實現(xiàn)XML與數(shù)據(jù)格式進行轉(zhuǎn)換類,實例分析了php進行XML格式數(shù)據(jù)的方法,具有一定參考借鑒價值,需要的朋友可以參考下2015-07-07php通過curl添加cookie偽造登陸抓取數(shù)據(jù)的方法
這篇文章主要介紹了php通過curl添加cookie偽造登陸抓取數(shù)據(jù)的方法,涉及PHP基于curl操作cookie及頁面抓取的相關(guān)技巧,需要的朋友可以參考下2016-04-04用mysql_fetch_array()獲取當前行數(shù)據(jù)的方法詳解
本篇文章是對使用mysql_fetch_array()獲取當前行數(shù)據(jù)的方法進行了詳細的分析介紹,需要的朋友參考下2013-06-06