【发布时间】:2016-11-24 08:10:50
【问题描述】:
我知道有很多关于这个问题的帖子。我尝试了一切,但没有成功。
我在我的 Windows 10 机器上使用 xampp v3.2.2。在我的 htdocs 中,我有一个名为 mysite 的项目。在那里我有codeigniter 3.0.3。
config.php
$config['base_url'] = 'http://localhost/mysite/';
$config['index_page'] = '';
routes.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/index”?
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 是否启用。
请帮帮我!
提前致谢, yab86
【问题讨论】:
-
添加到你的 route.php
$route['(:any)'] = 'CI_home/$1'; -
谢谢 MAZux。我试过了,但没有任何改变。
-
也尝试添加索引方法,尝试:
$route['(:any)'] = 'CI_home/index/$1'; -
你用的是wamp、xampp、lamp等哪一个
标签: php apache .htaccess codeigniter mod-rewrite