【发布时间】:2017-04-26 03:20:38
【问题描述】:
我想在 CI 3.x 中删除 index.php,我在 google 中关注所有 tut,这是我的代码:
控制器
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Danhmuc extends CI_Controller {
public function __construct()
{
parent::__construct();
//Load Dependencies
}
// List all your items
public function index( $offset = 0 )
{
}
public function add()
{
$this->load->view('danhmuc/danhmuc');
}
}
?>
在views/danhmuc/danhmuc.php中
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test</title>
</head>
<body>
Hello world
</body>
</html>
在 config.php 中
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
以及根目录下的 .htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
但是当我尝试http://localhost/cantin/danhmuc/add 时,显示未找到 404。但是当我尝试http://localhost/cantin/index.php/danhmuc/add 时,它就成功了。希望你能帮助我。谢谢!
【问题讨论】:
-
您是否在您的网络服务器上启用了重写模式?
-
@NguyenThanh rùi bạnơi, mình enable rùi, bạn xem trong git có đúng ko?
-
@thanhhuy12thh Không bạn ơi, ý mình là enable nó ở web server cơ, ko phải trong 代码。
标签: php .htaccess codeigniter codeigniter-3