Codeigniter 3删除index.php无法正常工作并抛出404 Page Not Found

时间:2018-01-10 18:57:01

标签: php .htaccess codeigniter codeigniter-3

我无法移除index.php

mod在我的apache中启用了Rewrite,我之前已经检查过了

我的网址

http://localhost/projects/ci/admin

这是我的控制器

class Admin extends CI_Controller{
    public function index()
    {
        echo "Admin Function";
    }
}

这是我的.htaccess文件,我从Codeigniter user_guide

复制
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

完成所有操作:

改变 $config['base_url'] = '';$config['base_url'] = 'http://localhost/projects/ci/';

$config['uri_protocol'] = 'REQUEST_URI';更改为$config['uri_protocol'] = 'AUTO';,反之亦然

$config['index_page'] = 'index.php';$config['index_page'] = ''; 在stackoverflow解决方案的帮助下但未能这样做。

2 个答案:

答案 0 :(得分:0)

在.htaccess文件中 复制以下代码并保存 然后尝试一下

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA] 

答案 1 :(得分:0)

我在正在开发的应用程序(使用CI)上共享我的配置

在文件../application/config/routes.php中,CI v3.1.6上的第53行

$route['default_controller'] = 'MyDefaultController';

的.htaccess

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

据我所知,如果你删除了index.php,如果所有你的系统文件都分配在你服务器上的../public_html文件夹中,那么你应该保留它,你应该保留它并进行更改,这样CI“知道“在哪里可以找到系统,应用程序和视图文件。

另外如果你删除了index.php并且没有在routes.php上设置默认控制器,(对不起我的英文)CI将找不到它的“索引页面”。

简而言之,检查routes.php上的默认控制器 希望它有所帮助。

相关问题