404页未找到错误的笨(404 page not found error in Codeignite

2019-09-26 02:39发布

我是新来的笨框架,我试图让我的第一个程序,但收到404 page not found错误

这是我的根目录Codeigniter ,我的目录结构

我的源文件夹中包含以下代码.htaccess文件

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]

Home.php

    class  Home extends CI_Controller{
    public function index(){
        $this->load->view('View');
    }
}

view.php

echo "HI this is my first codeigniter program";

我曾尝试以下URL http://localhost/Codeigniter/但我得到一个404错误,但是http://localhost/Codeigniter/home加载,即使我的实际根文件夹是笨正确的结果

如何解决这个问题呢?

Answer 1:

更改路由文件在此路径如下: -

CodeIgniter/application/config/routes.php

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

那么只有你可以访问以下网址

http://localhost/Codeigniter/


Answer 2:

尝试在那里

RewriteRule .* index.php/$0 [PT,L] 

改成

RewriteRule .* index.php/$1 [PT,L]

的.htaccess

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$1 [PT,L]

要么

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

更多的htaccess 这里

确保您的htaccess是应用程序文件夹之外。

然后在config.php文件

$config['base_url'] = 'http://localhost/codeigniter/'; 

$config['index_page'] = '';

然后你就可以在routes.php文件最好设置你的routes.php文件小写

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


文章来源: 404 page not found error in Codeigniter