去掉CI URL中index.php

喜你入骨 提交于 2019-11-27 07:15:32

apache服务器下

  • 首先配置apache支持rewrite,打开apache的配置文件,conf/httpd.conf :
    LoadModule rewrite_module modules/mod_rewrite.so,把该行前的#去掉。 修改<Directory "自己项目目录"></Directory>内的AllowOverride 为All
  • 在CI的根目录下,即在index.php的同级目录下,建立.htaccess,直接建立该文件名的不会成功,可以用其他工具创建editplus等。内容如下(CI手册上也有介绍):

    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'] = '';



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!