【问题标题】:404 page not found error in Codeigniter在 Codeigniter 中找不到 404 页面错误
【发布时间】:2016-12-11 18:48:57
【问题描述】:

我是 codeigniter 框架的新手,我尝试制作我的第一个程序,但收到 404 page not found 错误

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

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

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

主页.php

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

view.php

echo "HI this is my first codeigniter program";

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

如何解决这个问题?

【问题讨论】:

  • 检查路由文件CodeIgniter/application/config/routes.php中的默认控制器
  • 谢谢 Rajkumar .. 在我更改 $route['default_controller'] = 'Home'; 后它工作正常..

标签: php codeigniter


【解决方案1】:

在以下路径中更改路由文件:-

CodeIgniter/application/config/routes.php

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

那么只有你可以访问下面的url

http://localhost/Codeigniter/

【讨论】:

    【解决方案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 here

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

    然后在 config.php 上

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

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

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

    【讨论】:

      猜你喜欢
      • 2016-12-06
      • 1970-01-01
      • 2015-10-07
      • 2015-03-30
      • 1970-01-01
      • 1970-01-01
      • 2020-07-14
      • 2019-12-02
      相关资源
      最近更新 更多