【发布时间】:2021-08-09 07:46:51
【问题描述】:
如果有人在正确的 url 之后键入内容然后用户重定向到主页,我想将所有 404 错误自定义页面重定向到 codeigniter 中的主页。
【问题讨论】:
-
你能发布那个“正确的网址”吗?
标签: .htaccess codeigniter redirect
如果有人在正确的 url 之后键入内容然后用户重定向到主页,我想将所有 404 错误自定义页面重定向到 codeigniter 中的主页。
【问题讨论】:
标签: .htaccess codeigniter redirect
首先,进入 config -> routes,然后向下滚动直到找到
$route['404_override'] = 'error404'; //by default it's '' (empty)
其次,你创建一个控制器Error404.php
<?php
class Error404 extends CI_Controller
{
public function __construct()
{
parent::__construct();
}
public function index()
{
redirect('home'); //your controller (like Home.php or any controller that you want to call)
}
}
【讨论】:
<?php
class Error extends CI_Controller
{
function __construct()
{
parent::__construct();
}
function index(){
$this->load->view('home');
}
}
?>
【讨论】:
编辑error_404.php文件(FilePath: application/views/errors/html/error_404.php)
在</body> 标签之前添加您的代码,如下所示:
<?php
header("Location: $yourhomepageurl");
【讨论】: