我知道有很多帖子承认这个问题。我尝试了一切,但没有成功。
我在 Windows 10 机器上使用 xampp v3.2.2。在我的htdocs中,我得到了一个名为mysite的项目。在那里我有代码点火器 3.0.3。
配置.php
$config['base_url'] = 'http://localhost/mysite/';
$config['index_page'] = '';
路线.php
$route['default_controller'] = 'CI_home';
控制器CI_home.php:
class CI_home extends CI_Controller{
function __construct() {
parent::__construct();
}
public function index($lang = ''){
$this->load->helper('url');
$this->load->helper('language');
$this->lang->load($lang, $lang);
$this->load->view('view_home');
}
}
当我调用http://localhost/mysite
时,页面显示正确。
问题是,当我尝试http://localhost/mysite/en
或http://localhost/mysite/index/en
时,我收到了来自 xampp 的 404。
但是如果我尝试http://localhost/mysite/index.php/CI_home/index/en
它工作正常。
我做错了什么?如何删除"CI_home/索引"?
http://localhost/mysite/.htaccess:
.htaccess
RewriteEngine On
RewriteCond $1 !^(index'.php|resources|robots'.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
我已经检查了mod_rewrite是否已启用。
请帮帮我!
提前感谢,亚布86
试试下面的htaccess
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index'.php|images|robots'.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
确保 htaccess 在您的主目录中。
然后设置基本网址
$config['base_url'] = 'http://localhost/yourproject/';
然后删除索引.php
$config['index_page'] = '';
注意:Codeigniter 3 版本区分大小写。确保只有类和文件名的第一个字母大写。
<?php
class Ci_home extends CI_Controller {
public function __construct() {
parent::__construct();
}
public function index($lang = '') {
$this->load->helper('url');
$this->load->helper('language');
$this->lang->load($lang, $lang);
$this->load->view('view_home');
}
}
然后确保文件名为Ci_home.php
那么您的默认路由应该是
使用默认控制器时,请确保与所选控制器同名。
URI 路由
$route['default_controller'] = 'ci_home';
$route['(:any)'] = 'ci_home/index/$1';