简体   繁体   English

404页面不存在。 未找到您所请求的页面。 Codeigniter 3.0.6

[英]404 Page Not Found. The page you requested was not found. Codeigniter 3.0.6

i have problem with CodeIgniter3: 404 Page Not Found 我对CodeIgniter3有问题:找不到404页

File: application/controllers/Welcome.php 文件: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');
    }
}

File: application/config/autoload/php 文件:application / config / autoload / php

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

File: application/config/routes.php 文件:application / config / routes.php

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

File: application/config/config.php 文件:application / config / config.php

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

File: .htaccess 档案:.htaccess

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

Page loads Welcome_Page, but not other pages. 页面加载Welcome_Page,但不加载其他页面。

404 Page Not Found

The page you requested was not found.

In folder views, exist pages: Forum_Page.php, Login_Page.php, Manual_Page.php, Register_Page.php, Tutorial_Page.php and Welcome_Page.php 在文件夹视图中,存在以下页面:Forum_Page.php,Login_Page.php,Manual_Page.php,Register_Page.php,Tutorial_Page.php和Welcome_Page.php

Thank you so much for understanding! 非常感谢您的理解!

Try this. 尝试这个。 Replace your .htaccess code with the following code: YOURPROJECTNAME is your base folder. 将您的.htaccess代码替换为以下代码:YOURPROJECTNAME是您的基本文件夹。 eg if you are on local server and your project is called myproblem, then replace 'YOURPROJECTNAME' with 'myproblem' 例如,如果您在本地服务器上并且您的项目名为myproblem,则将“ YOURPROJECTNAME”替换为“ myproblem”

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

ensure that the .htaccess is at the root of your app also. 确保.htaccess也位于应用程序的根目录下。

Ah, I see now. 啊,我明白了。 Your problem is in routing. 您的问题在于路由。 You are meant to reach pages as 您本应以

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

but you created view HTML to get 但是您创建了视图HTML以获取

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

In APPPATH.'config/routes.php' file, under reserved routes you have to reroute your calls in way of: APPPATH.'config/routes.php'文件中,在保留的路由下,您必须通过以下方式重新路由呼叫:

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

Two things are here you need to pay attention: 这里有两件事需要注意:

  1. Placeholder (:any) would take place for $1 , 占位符(:any)费用为$1
  2. Your route that contains (:any) parameter have to be at the end of file because 包含(:any)参数的路由必须在文件末尾,因为

    Routes will run in the order they are defined. 路线将按照定义的顺序运行。 Higher routes will always take precedence over lower ones. 较高的路线将始终优先于较低的路线。

More of that here . 这里更多。 Check that whole page and other pages in docs as well. 检查整个页面以及文档中的其他页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM