我正在使用codeigniter 3.我创建了一个简单的控制器,当我尝试访问控制器时出现404错误。
我的控制器
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class home extends CI_Controller {
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* @see http://codeigniter.com/user_guide/general/urls.html
*/
public function index()
{
echo "Working fine";
$this->load->view('comman/header.php');
$this->load->view('home/home.php');
}
}
配置文件
$config['base_url'] = 'http://localhost/annaiplan/';
$config['index_page'] = 'index.php';
$config['url_suffix'] = '';
的.htaccess
Options +FollowSymLinks
RewriteEngine on
RewriteBase /annaiplan
RewriteCond $1 !^(index\\.php|resources|robots\\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
当我尝试访问该应用时遇到404错误。
http://localhost/annaiplan/home/
答案 0 :(得分:1)
首先总是控制器文件名应该是&#39; Home&#39;并且在类中它的类名应该是Home扩展....其次你需要从routes.php更改默认控制器 rout.php ====的路径 根文件夹/ application / config / routes.php
从$route['default_controller'] = 'welcome';
更改为$route['default_controller'] = 'Home
&#39;;
答案 1 :(得分:0)
在htaccess文件中
变化:
RewriteBase /annaiplan
致:
RewriteBase /
你也可以用这个替换htaccess代码。
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^system.*
RewriteCond $1 !^(index\.php|images|js|uploads|css|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]