去掉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'] = '';
相关文章
相关标签/搜索