【问题标题】:404 Page Not Found. The page you requested was not found. Codeigniter 3.0.6404页面不存在。未找到您所请求的页面。 Codeigniter 3.0.6
【发布时间】:2016-10-08 11:02:35
【问题描述】:

我遇到了 CodeIgniter3 的问题:找不到 404 页面

文件:application/controllers/Welcome.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {   
    public function __construct()
    {
        parent::__construct();
    }
    public function index()
    {
        $this->load->view('Welcome_Page');
    }
    public function tutorial()
    {
        $this->load->view('Tutorial_Page');
    }
    public function manual()
    {
        $this->load->view('Manual_Page');
    }
    public function forum()
    {
        $this->load->view('Forum_Page');
    }
    public function register()
    {
        $this->load->view('Register_Page');
    }
    public function login()
    {
        $this->load->view('Login_Page');
    }
}

文件:application/config/autoload/php

$autoload['helper'] = array('url');

文件:application/config/routes.php

$route['default_controller'] = 'welcome';
$route['translate_uri_dashes'] = FALSE;

文件:application/config/config.php

$config['base_url'] = 'http://subdomain.domain.tld';
$config['index_page'] = '';

文件:.htaccess

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

页面加载 Welcome_Page,但不加载其他页面。

404 Page Not Found

The page you requested was not found.

在文件夹视图中,存在页面:Forum_Page.php、Login_Page.php、Manual_Page.php、Register_Page.php、Tutorial_Page.php 和 Welcome_Page.php

非常感谢您的理解!

【问题讨论】:

  • 显示您尝试访问的 URL。 base_url中应该有一个斜杠
  • 我试过了:$config['base_url'] = 'subdomain.domain.tld'; ...不工作。
  • 尝试更改RewriteRule ^(.*)$ index.php?/$1 [L]
  • 我没有得到另一个结果 :(
  • @AurelBercea 向我们展示您的现场地址

标签: php .htaccess codeigniter model-view-controller codeigniter-3


【解决方案1】:

试试这个。用以下代码替换您的 .htaccess 代码: YOURPROJECTNAME 是您的基本文件夹。例如如果您在本地服务器上并且您的项目名为 myproblem,则将 'YOURPROJECTNAME' 替换为 'myproblem'

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

确保 .htaccess 也位于应用的根目录中。

【讨论】:

  • 我显示错误:500 Internal Server Error 发生内部服务器错误。
  • 您的应用程序是否在本地服务器上运行?
  • 否...在共享服务器上运行
  • 将代码替换为(当我在公共域上运行时它适用于我): RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} ! -d RewriteRule ^(.*)$ index.php?/$1 [L] ErrorDocument 404 /index.php
【解决方案2】:

啊,我明白了。您的问题在于路由。您访问网页的目的是

http://sub.domain.tld/welcome/tutorial
http://sub.domain.tld/welcome/manual
...

但是你创建了视图 HTML 来获取

http://sub.domain.tld/tutorial
http://sub.domain.tld/manual
...

APPPATH.'config/routes.php' 文件中,在保留路由下,您必须通过以下方式重新路由呼叫:

$config[(:any)] = 'welcome/$1'

这里有两点需要注意:

  1. 占位符(:any) 将用于$1
  2. 包含(:any) 参数的路由必须位于文件末尾,因为

    路由将按照它们定义的顺序运行。较高的路线总是优先于较低的路线。

更多 here。检查整个页面和文档中的其他页面。

【讨论】:

  • #SOreadytohelp 请随意to accept(并点赞),因为它解决了您的问题,帮助其他人更轻松地找到解决方案。
猜你喜欢
  • 2017-11-16
  • 2021-07-04
  • 2018-04-18
  • 2016-01-12
  • 2013-07-06
  • 2012-12-30
  • 2012-08-18
  • 1970-01-01
  • 2017-03-07
相关资源
最近更新 更多