从 CodeIgniter 中删除 index.php

Posted

技术标签:

【中文标题】从 CodeIgniter 中删除 index.php【英文标题】:Remove index.php from CodeIgniter 【发布时间】:2014-09-20 21:37:12 【问题描述】:

我使用 CodeIgniter 2.2.0 和 AppServ 2.5.10 作为本地服务器。 在 config.php 我确定来自: $config['index_page'] = ''; 这是根文件夹中的 .htaccess(护理):

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /nursing/

#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %REQUEST_URI ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %REQUEST_URI ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

ErrorDocument 404 /index.php
</IfModule>

当我尝试访问:localhost/nursing/welcome/index 时,AppServ 欢迎页面出现了!,而不是应有的欢迎控制器!

【问题讨论】:

尝试把这个.htaccess 放到/nursing/.htaccess 并且把RewriteBase 改成/(而不是/nursing/) 【参考方案1】:

我的 .htaccess 在这里:

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteCond $1 !^(index\.php|templates|payment\.php)
   RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
   ErrorDocument 404 /index.php
</IfModule>

【讨论】:

系统真的安装了模块吗?此代码已在我的生产环境和工作环境中验证。【参考方案2】:

mod 重写模块被 httpd.conf 禁用

【讨论】:

【参考方案3】:

在 .htaccess 中编写这段代码

RewriteEngine On
RewriteCond %REQUEST_URI ^/system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule ^(.+)$ index.php?/$1 [L]

【讨论】:

以上是关于从 CodeIgniter 中删除 index.php的主要内容,如果未能解决你的问题,请参考以下文章

强制从 codeigniter 中删除 index.php

从 URL 中删除 index.php (CodeIgniter)

CodeIgniter - 从 URL 中删除“索引”

从 CodeIgniter 中删除 index.php

从 url (codeigniter) 中删除 index.php 时 .htaccess 防止显示文件

从 codeigniter url 中删除 index.php