404 page not found error in Codeigniter

时光怂恿深爱的人放手 提交于 2020-01-05 04:43:15

问题


I am new to the codeigniter framework and I have tried to make my first program but received a 404 page not found error

This is my root directory Codeigniter and my directory structure

My source folder contains the .htaccess file containing the following code

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";

I have tried the following url http://localhost/Codeigniter/ but I get a 404 error, however http://localhost/Codeigniter/home loads the correct result even though my actual root folder is Codeigniter

how to solve this problem?


回答1:


Change route file in this following path:-

CodeIgniter/application/config/routes.php

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

Then only you can access the following url

http://localhost/Codeigniter/



回答2:


Try where

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

change to

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

.htaccess

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

Or

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]

More htaccess here

Make sure your htaccess is outside of application folder.

And then on config.php

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

$config['index_page'] = '';

And then you can set your routes.php lower case best on routes.php

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


来源:https://stackoverflow.com/questions/38787790/404-page-not-found-error-in-codeigniter

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