去掉CI URL中index.php

apache服務器下 php

  • 首先配置apache支持rewrite,打開apache的配置文件,conf/httpd.conf :
    LoadModule rewrite_module modules/mod_rewrite.so,把該行前的#去掉。 修改<Directory "本身項目目錄"></Directory>內的AllowOverride 爲All
  • 在CI的根目錄下,即在index.php的同級目錄下,創建.htaccess,直接創建該文件名的不會成功,能夠用其餘工具建立editplus等。內容以下(CI手冊上也有介紹): css

    RewriteEngine on  
    RewriteCond $1 !^(index\.php|images|robots\.txt)  
    RewriteRule ^(.*)$ /index.php/$1 [L]
    若是文件不是在apache項目的根目錄下,例如http://www.xxx.net/CodeIgniter/,第三行須要改寫爲RewriteRule ^(.*)$ /CodeIgniter/index.php/$1 [L]。個人index.php的同級目錄下還有js文件夾和css文件夾,這些須要過濾除去,第二行須要改寫爲:RewriteCond $1 !^(index\.php|images|js|css|robots\.txt)
  • 將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'] = '';
相關文章
相關標籤/搜索