404页面不存在。未找到您所请求的页面。代码点火器 3.0.6
404 Page Not Found. The page you requested was not found. Codeigniter 3.0.6
我遇到 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/ [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
非常感谢您的理解!
试试这个。用以下代码替换您的 .htaccess 代码:YOURPROJECTNAME 是您的基本文件夹。例如如果您在本地服务器上并且您的项目名为 myproblem,则将 'YOURPROJECTNAME' 替换为 'myproblem'
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* YOURPROJECTNAME/index.php/[=10=] [PT,L]
确保 .htaccess 也位于您的应用程序的根目录中。
啊,我明白了。你的问题出在路由上。您应该以
访问页面
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/'
这里有两点需要注意:
- 占位符
(:any)
将用于 </code>、</li>
<li>包含 <code>(:any)
参数的路由必须位于文件末尾,因为
Routes will run in the order they are defined. Higher routes will always take precedence over lower ones.
更多 here。还要检查整个页面和文档中的其他页面。
我遇到 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/ [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
非常感谢您的理解!
试试这个。用以下代码替换您的 .htaccess 代码:YOURPROJECTNAME 是您的基本文件夹。例如如果您在本地服务器上并且您的项目名为 myproblem,则将 'YOURPROJECTNAME' 替换为 'myproblem'
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* YOURPROJECTNAME/index.php/[=10=] [PT,L]
确保 .htaccess 也位于您的应用程序的根目录中。
啊,我明白了。你的问题出在路由上。您应该以
访问页面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/'
这里有两点需要注意:
- 占位符
(:any)
将用于</code>、</li> <li>包含 <code>(:any)
参数的路由必须位于文件末尾,因为Routes will run in the order they are defined. Higher routes will always take precedence over lower ones.
更多 here。还要检查整个页面和文档中的其他页面。